1

I cannot figure out why this gives me a syntax error when trying to update this?

string editComp = "UPDATE Competitive SET (PartNumber, Location, Description) values (@Edpart, @Edlocation, @Eddescrip) where SerialNumber = @serial";
command.CommandText = editComp;
command.Parameters.Add("@serial", OleDbType.VarChar).Value = Serialtext.Text;
command.Parameters.Add("@Edpart", OleDbType.VarChar).Value = Parttext.Text;
command.Parameters.Add("@Edlocation", OleDbType.VarChar).Value = cboLocation.Text;
command.Parameters.Add("@Eddescrip", OleDbType.VarChar).Value = Descriptiontext.Text;
command.ExecuteNonQuery();
MessageBox.Show("Successfully Updated");
1
  • What database are you using? Commented Jun 29, 2016 at 1:28

1 Answer 1

2

You are trying to execute an update query with syntax of an insert. use correct syntax for UPDATE like the following;

 string editComp = "UPDATE Competitive SET PartNumber=@Edpart, Location=@Edlocation, Description=@Eddescrip";

If the above code is not working then try replacing @Edlocation,@Eddescrip and @Edpart with ?

Sign up to request clarification or add additional context in comments.

5 Comments

Well I changed to the above and added this to the end - WHERE SerialNumber=@serial. It says it has updated but it doesn't actually update.
The add, delete statements I put in work just fine with "@" .
enclose the statements within a try and check whether any exception is comming
I already have it enclosed , that's why I was getting the syntax error from before. Now it shows my message box but no actual update.
Got it!,,,,By adding the serial number parameter first but not using it until the end of the statement it would not work. Moved the serial number to the end of the parameters I added and now it works, thank you for getting me started.

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.