Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
hey all,
I have a problem that when ever I try to update a record in the database using gridview update event handler and an updatecommand in sqldatascource
I get the following exception
Incorrect syntax near 'int'.
the weird thing is when I reload the page I find that the record was updated successfully but yet I need this exception message not to appear what should I do

update event handler
C#
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{

        GridViewRow row = GridView1.Rows[e.RowIndex];
        int BusId = Convert.ToInt32(((DataKey)GridView1.DataKeys[e.RowIndex]).Value);
        TextBox Capacity =(TextBox) row.Cells[1].Controls[0];
        TextBox DriverName =(TextBox) row.Cells[3].Controls[0];
        TextBox Phone =(TextBox) row.Cells[4].Controls[0];
        SqlDataSource1.UpdateParameters.Add("capaity", Capacity.Text);
        SqlDataSource1.UpdateParameters.Add("id", BusId.ToString());
        SqlDataSource1.UpdateParameters.Add("driver", DriverName.Text);
        SqlDataSource1.UpdateParameters.Add("phone", Phone.Text);
        SqlDataSource1.Update();
}


gridview asp.net code

ASP.NET
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4" DataKeyNames="Bus Number" DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None" Height="326px" Width="1017px" OnRowUpdating="GridView1_RowUpdating">
    <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
    <Columns>
        <asp:BoundField DataField="Bus Number" HeaderText="Bus Number" ReadOnly="True" SortExpression="Bus Number" />
        <asp:BoundField DataField="Capacity" HeaderText="Capacity" SortExpression="Capacity" />
        <asp:BoundField DataField="NumberOfBooking" HeaderText="NumberOfBooking" SortExpression="NumberOfBooking" ReadOnly="True" />
        <asp:BoundField DataField="Driver" HeaderText="Driver" SortExpression="Driver" />
        <asp:BoundField DataField="Phone" HeaderText="Phone" SortExpression="Phone" ShowHeader="False" />
        <asp:BoundField DataField="Date Added" HeaderText="Date Added" SortExpression="Date Added" DataFormatString="{0:MM/dd/yyyy}" ReadOnly="True" />
        <asp:CommandField ShowEditButton="True" />
        <asp:CommandField ShowDeleteButton="True" />
    </Columns>
    <EditRowStyle BackColor="#999999" />
    <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
    <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
    <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
    <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
    <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
    <SortedAscendingCellStyle BackColor="#E9E7E2" />
    <SortedAscendingHeaderStyle BackColor="#506C8C" />
    <SortedDescendingCellStyle BackColor="#FFFDF8" />
    <SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>


the updatecommand
HTML
UpdateCommand="UPDATE Buses SET Capacity = @capaity WHERE VechileId = @id;UPDATE Vechile SET Driver = @driver, Phone = @phone WHERE VechileId = @id">
Posted
Updated 2-May-13 5:26am
v2
Comments
ZurdoDev 2-May-13 12:14pm    
Is the error coming from a trigger?
Scarnet 2-May-13 12:18pm    
It happens after I press update on the gridview
ZurdoDev 2-May-13 12:32pm    
I understand that. But you said it does get updated which means your update statement runs. I also don't see where the syntax error is which makes me think the issue is in a SQL trigger.
Scarnet 2-May-13 12:44pm    
first of all thanks for ur patience
and no I didn't write any sql triggers
ZurdoDev 2-May-13 13:40pm    
Use SQL profiler then and see what the actual SQL is that is getting sent to SQL.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900