Problem with parameterized update query
I am using the following code to try and update a database entry, the UPDATE statement works when i am not using parameters but when i am using them it seems to do absolutely nothing. No error and no update either.
PHP Code:
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("@field2 ", txtTwo.Text)
dbCommand.Parameters.AddWithValue("@field3 ", txtThree.Text)
dbCommand.Parameters.AddWithValue("@currentValue", lstListBox.SelectedValue)
dbCommand.ExecuteNonQuery()
Can anyone tell me why this isnt working?
Re: Problem with parameterized update query
you've missed matched the parameter names...
field1 = @value1, field2 = @value2, field3 = @value3
and then..
dbCommand.Parameters.AddWithValue("@value1", txtOne.Text)
dbCommand.Parameters.AddWithValue("@field2", txtTwo.Text)
dbCommand.Parameters.AddWithValue("@field3", txtThree.Text)
Also take the space out of the parameters name....
Re: Problem with parameterized update query
Actually that was just a mistake when i was posting the code, i changed the parameter names from what i actually have in my code and accidentally put @field instead of @value. In my code they are actually correct. That wasnt the source of the problem.