1

Could Someone please assist me with this simple error I have been struggling with for the last couple of hours? I am at the point of just burning the laptop....

Error: [SqlException (0x80131904): Incorrect syntax near the keyword 'Group'.]

Code:

  Protected Sub GridView1_RowUpdating(sender As Object, e As System.Web.UI.WebControls.GridViewUpdateEventArgs)
    Dim ID As Label = TryCast(GridView1.Rows(e.RowIndex).FindControl("lbl_ID"), Label)
    Dim AID As TextBox = TryCast(GridView1.Rows(e.RowIndex).FindControl("txt_AID"), TextBox)
    Dim ADesc As TextBox = TryCast(GridView1.Rows(e.RowIndex).FindControl("txt_ADesc"), TextBox)
    Dim Status As TextBox = TryCast(GridView1.Rows(e.RowIndex).FindControl("txt_Status"), TextBox)
    Dim ADate As TextBox = TryCast(GridView1.Rows(e.RowIndex).FindControl("txt_ADate"), TextBox)
    Dim Category As TextBox = TryCast(GridView1.Rows(e.RowIndex).FindControl("txt_Category"), TextBox)
    Dim Location As TextBox = TryCast(GridView1.Rows(e.RowIndex).FindControl("txt_Location"), TextBox)
    Dim CCenter As TextBox = TryCast(GridView1.Rows(e.RowIndex).FindControl("txt_CCenter"), TextBox)
    Dim Group As TextBox = TryCast(GridView1.Rows(e.RowIndex).FindControl("txt_Group"), TextBox)
    Dim Life As TextBox = TryCast(GridView1.Rows(e.RowIndex).FindControl("txt_Life"), TextBox)
    Dim BValue As TextBox = TryCast(GridView1.Rows(e.RowIndex).FindControl("txt_BValue"), TextBox)
    Dim RRate As TextBox = TryCast(GridView1.Rows(e.RowIndex).FindControl("txt_RRate"), TextBox)
    Dim RType As TextBox = TryCast(GridView1.Rows(e.RowIndex).FindControl("txt_RType"), TextBox)
    con = New SqlConnection(cs)
    con.Open()

    Dim sqlString As String = "UPDATE Asset_Registry SET Asset_ID=@AID,Asset_Description=@ADesc,Status=@Status,Acquisition_Date=@ADate,Category=@Category,Location=@Location,Cost_Center=@CCenter,Group=@Group,Life=@Life,Book_Value=@BValue,Rental_Rate=@RRate,Rental_Type=@RType WHERE ID=@ID"
    Dim cmd As New SqlCommand(sqlString, con)
    cmd.Parameters.AddWithValue("@AID", AID.Text)
    cmd.Parameters.AddWithValue("@ADesc", ADesc.Text)
    cmd.Parameters.AddWithValue("@Status", Status.Text)
    cmd.Parameters.AddWithValue("@ADate", ADate.Text)
    cmd.Parameters.AddWithValue("@Category", Category.Text)
    cmd.Parameters.AddWithValue("@Location", Location.Text)
    cmd.Parameters.AddWithValue("@CCenter", CCenter.Text)
    cmd.Parameters.AddWithValue("@Group", Group.Text)
    cmd.Parameters.AddWithValue("@Life", Life.Text)
    cmd.Parameters.AddWithValue("@BValue", BValue.Text)
    cmd.Parameters.AddWithValue("@RRate", RRate.Text)
    cmd.Parameters.AddWithValue("@RType", RType.Text)

    cmd.ExecuteNonQuery()
    con.Close()
    GridView1.EditIndex = -1
    ShowData()
End Sub
2
  • 2
    Reserved word, delimit it! Commented Oct 16, 2017 at 10:37
  • print query and check. What is missing? Commented Oct 16, 2017 at 10:37

1 Answer 1

1

GROUP is a reserved word in SQL Server, escape it with []:

UPDATE Asset_Registry 
SET Asset_ID=@AID,
    Asset_Description=@ADesc,
    ...
    [Group]=@Group -- <-----
    ...
WHERE ID=@ID
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.