1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2012
    Rep Power

    Problem with parameterized update query

    I am trying to update a database entry using a parameterized query, but for some reason it doesnt seem to want to work. The update statement works without the parameters there, but with them nothing happens. No errors, no crashes, and no update either.

    This is the code i use:

    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) 
    Can anyone tell me what i am doing wrong with the code?
  2. #2
  3. No Profile Picture
    Grumpier old Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2003
    Rep Power
    I don't know the syntax for parameterized queries. I think you can instpect the values in your command object before executing the query, perhaps one of the parameter vaules is invalid. Make sure you are updating the proper database. Look for any "on error resume next" statements in your asp code that may be hiding errors.
    Doug G
    I've never been able to appreciate the sublime arrogance of folks who feel they were put on earth just to save other folks from themselves .." - Donald Hamilton

IMN logo majestic logo threadwatch logo seochat tools logo