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

    Join Date
    Mar 2012
    Posts
    15
    Rep Power
    0

    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:

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

    Join Date
    Jun 2003
    Posts
    14,409
    Rep Power
    4538
    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
    ======
    It is a truism of American politics that no man who can win an election deserves to. --Trevanian, from the novel Shibumi

IMN logo majestic logo threadwatch logo seochat tools logo