I am trying to use a parameterized query to update entries in a mysql database, however it wont update anything.
This is the code i am using:
Yes i connect to the database, yes i open the connection. I have a SELECT statement that displays the data from the database so i know everything is set up to connect to it fine. The problem seems to lie with the parameters, when i tried to put single quotes ' ' around the @value1 parameter it ignore the parameter and added @value1 to the database so the update statement seems to work.
Can anyone tell me what is wrong with it?
This is the code i am using:
sqlString = "UPDATE table SET field1 = @value1, field2 = @value2, field3 = @value3 WHERE field1 = @currentValue" dbCommand.CommandText = sqlString dbCommand.Parameters.AddWithValue("@value1", txtOne.Text) dbCommand.Parameters.AddWithValue("@value2 ", txtTwo.Text) dbCommand.Parameters.AddWithValue("@value3 ", txtThree.Text) dbCommand.Parameters.AddWithValue("@currentValue", lstListBox.SelectedValue) dbCommand.ExecuteNonQuery()
Yes i connect to the database, yes i open the connection. I have a SELECT statement that displays the data from the database so i know everything is set up to connect to it fine. The problem seems to lie with the parameters, when i tried to put single quotes ' ' around the @value1 parameter it ignore the parameter and added @value1 to the database so the update statement seems to work.
Can anyone tell me what is wrong with it?