Skip to content

System.Data.SqlClient.SqlException occured in System.Data.dll (incorrect syntax)

I can’t work out what the problem is here, since the additional information comes back as: Incorrect Syntax near ‘(‘. I think I need fresh eyes on this I can’t see the error.

Here is my code, im trying to update the information to the selected Owner_ID.

 System.Data.SqlClient.SqlCommand command = new SqlCommand("UPDATE OwnerTable SET (Owner_ID, Owner_Fname, Owner_Lname, Owner_HouseNo, Owner_Street, Owner_County, Owner_PostCode, Owner_Tele, Owner_Email) VALUES (@OwnerID, @OwnerFName, @OwnerLName, @OwnerHouseNo, @OwnerStreet, @OwnerCounty, @OwnerPostCode, @OwnerTele, @OwnerEmail) WHERE Owner_ID = @OwnerID", connection);

            command.CommandType = CommandType.Text;
            command.Connection = connection;

            command.Parameters.AddWithValue("@OwnerID", CB_OWNER_ID.GetItemText(CB_OWNER_ID.SelectedItem));

            command.Parameters.AddWithValue("@OwnerFName", TXT_OWNER_FNAME.Text);
            command.Parameters.AddWithValue("@OwnerLName", TXT_OWNER_LNAME.Text);
            command.Parameters.AddWithValue("@OwnerHouseNo", TXT_OWNER_HOUSENO.Text);
            command.Parameters.AddWithValue("@OwnerStreet", TXT_OWNER_STREET.Text);
            command.Parameters.AddWithValue("@OwnerCounty", TXT_OWNER_COUNTY.Text);
            command.Parameters.AddWithValue("@OwnerPostCode", TXT_OWNER_POSTCODE.Text);
            command.Parameters.AddWithValue("@OwnerTele", TXT_OWNER_TELE.Text);
            command.Parameters.AddWithValue("@OwnerEmail", TXT_OWNER_EMAIL.Text);



You used INSERT syntax instead of UPDATE syntax:

UPDATE OwnerTable SET Owner_ID = @OwnerID, Owner_Fname = @OwnerFName ..etc

Or if you indeed wanted to insert a new record change UPDATE to INSERT INTO and remove the WHERE (but I guess the WHERE indicates that you wanted to update).

Btw: are you sure to update the OwnerID in the OwnerTable? Seems wrong to me.

3 People found this is helpful