chan
chan

Reputation: 1

Getting the error "Query input must contain at least one table or query."

I am using visual studio 2010 to create a form where you can edit,delete, or insert data from an accessdatabase. When I try to run the form in a web browser I get the error "Query input must contain at least one table or query." I believe that the problem lies with my code/syntax but I am unable to determine the cause of the problem. I added some of my code below and any help/hints would be greatly appreciated. Thank You.

<asp:AccessDataSource ID="AccessDataSource1" runat="server" 
            DataFile="~/App_Data/database.accdb" SelectCommand="SELECT * FROM [database]"
            DeleteCommand="DELETE FROM [database] WHERE ([EmployeeID] = @EmployeeID)"
            UpdateCommand="UPDATE [database] SET [Phone]=@Phone,[FirstName] = @FirstName, [LastName]= @LastName  WHERE ([EmployeeID] = @EmployeeID)"
            InsertCommand="INSERT INTO [database] (Phone,FirstName,LastName) VALUES (@Phone,@FirstName,@LastName) WHERE ([EmployeeID] = @EmployeeID)">
            <InsertParameters>
             <asp:formparameter name="Phone" formfield="tbPhone" />
             <asp:formparameter name="FirstName"  formfield="tbFirstName" />
             <asp:formparameter name="LastName"  formfield="tbLastName" />
            </InsertParameters>
        </asp:AccessDataSource>
        <asp:GridView ID="gvEmployee" runat="server" AutoGenerateColumns="False" 
            DataSourceID="AccessDataSource1" DataKeyNames="EmployeeID"
            AutoGenerateDeleteButton="True" AutoGenerateEditButton="True" AutoGenerateInsertButton="True"
            EmptyDataText="There are no data records to display." Width="372px">
            <Columns>
                <asp:BoundField DataField="Phone" HeaderText="Phone"
                     SortExpression="Phone" />
                <asp:BoundField DataField="FirstName" HeaderText="FirstName" 
                    SortExpression="FirstName" />
                <asp:BoundField DataField="LastName" HeaderText="LastName" 
                    SortExpression="LastName" />

            </Columns>
        </asp:GridView>        
    </td>
     </tr>
    <tr>
    <td>
        Phone Number: 
        <asp:TextBox ID="tbPhone" runat="server"></asp:TextBox><br /> 
        First Name:
        <asp:TextBox ID="tbFirstName" runat="server"></asp:TextBox> <br /> 
        Last Name:&nbsp;
        <asp:TextBox ID="tbLastName" runat="server"></asp:TextBox> <br />           
        <asp:button id="Button1" runat="server" text="New Employee" onclick="InsertEmployee" />
    </td>
    </tr>

Upvotes: 0

Views: 1847

Answers (1)

Sparky
Sparky

Reputation: 15095

What is [Database]? Is that your table name? You need to specify a table name, such as PERSONS, or Employees?

SELECT * FROM [database]

try something like

SELECT * FROM Employee

Try this now

SELECT Phone,FirstName,LastName,EmployeeID FROM [employees]

If that works, it means some sort of field in the Employees table is something that can't be handled... Since the above triggers an error, it means the code can't handle an Autonum field. Try the following:

SELECT Phone,FirstName,LastName,CAST(EmployeeID as INT) as EmployeeID 
       FROM [employees]

Try taking the where clause entirely off the INSERT SQL

  InsertCommand="INSERT INTO [database] (Phone,FirstName,LastName) VALUES (@Phone,@FirstName,@LastName) "

Upvotes: 1

Related Questions