Link to home
Start Free TrialLog in
Avatar of rito1
rito1

asked on

Syntax error in UPDATE statement Using OleDb and MS Access

Hi,

I have used VS 2005 to create an update statement to an Access table but it is throwing the following error:

System.Data.OleDb.OleDbException: Syntax error in UPDATE statement.

The AccessDataSource control's SQL Statement and parameters look like so...

UpdateCommand="UPDATE [tblCustomers] SET [Customer_name] = ?, [Customer_Username] = ?, [Customer_Password] = ?, [Customer_Live] = ?, WHERE [CustomerID] = ?"

Parameters -

<UpdateParameters>
            <asp:Parameter Name="Customer_name" Type="String" />
            <asp:Parameter Name="Customer_Username" Type="String" />
            <asp:Parameter Name="Customer_Password" Type="String" />
            <asp:Parameter Name="Customer_Live" Type="Boolean" />
            <asp:Parameter Name="CustomerID" Type="Int32" />
        </UpdateParameters>

Is anyone able to see any issues?

Many thanks,

Rit
SOLUTION
Avatar of rpkhare
rpkhare
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rito1
rito1

ASKER

Hi rpkhare

The string values are coming straigh from the Gridview as I am using the Update command button.

The data type Customer_Live was Yes/No but have just changed it to True/False but still getting this error.

My gridview looks like this...



<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="CustomerID" DataSourceID="AccessDataSource1" Width="100%" CellPadding="4" AlternatingRowStyle-BackColor="#eeeeee" BorderWidth="1px" BorderColor="#EEEEEE">
        <Columns>
            <asp:BoundField DataField="Customer_name" HeaderText="Customer Name" SortExpression="Customer_name" />
            <asp:BoundField DataField="Customer_Username" HeaderText="Username" SortExpression="Customer_Username" />
            <asp:BoundField DataField="Customer_Password" HeaderText="Password" SortExpression="Customer_Password" />
            <asp:CheckBoxField DataField="Customer_Live" HeaderText="Live?" SortExpression="Customer_Live" />
            <asp:CommandField ShowEditButton="True" />
            <asp:TemplateField ShowHeader="False">
                <ItemTemplate>
                    <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Delete" Text=" X " OnClientClick="return confirm('Are you sure you want to delete this record?');" ForeColor="red"></asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>

Open in new window

I think you need to still add single quotes in the query:

UpdateCommand="UPDATE [tblCustomers] SET [Customer_name] = ' " + <GridViewValue> + " ' "
ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
emoreau, Yes you got it. I think that is the problem.
Avatar of rito1

ASKER

Thanks emoreau, I would have been there for ages! Thanks rpkhare for your support too.