Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Whats wrong with this parameterized update query?

$
0
0
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:

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?

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>