Helpful Information
 
 
Category: ASP.NET
Syntax error in UPDATE statement

The following code generates an error and I am not sure why. Anyone have any ideas?

cmdString2 = string.Format( "UPDATE USERS SET password='" & txtConfirmPassword.Text & "' WHERE username='" & dtrResults("username") & "'")

cmdUpdate = New OleDbCommand( cmdString2, conLogin2 )

conLogin2.Open()
cmdUpdate.ExecuteNonQuery()
conLogin2.Close()

When I display the update statement it looks like this:

UPDATE USERS SET password='pswrd' WHERE username='usrname'

I am pretty sure that is ok, but it errors out on the line cmdUpdate.ExecuteNonQuery()

Thank you for any advice.

cbowen2

Try adding squar brackets '[]' around the password field, as i'm sure it's a reserved word:


cmdString2 = string.Format( "UPDATE USERS SET [password]='" & txtConfirmPassword.Text & "' WHERE username='" & dtrResults("username") & "'")


Good luck :)

You are a life saver, thank you very much!

thank you Brando

that is also my problem and when i read it i put a bracket on every field i want to update

Thanx ! really this is a big problem.very thanx.


http://homefitnessandnutrition.co.cc/dvd-workout-reviews/some-guidelines-for-best-indoor-cycling-skill/

Hi

I have a similar problem..,,this is my code

Dim cb As New OleDb.OleDbCommandBuilder(da)

ds.Tables("Inventory").Rows(inc).Item(0) = txtProductName.Text
ds.Tables("Inventory").Rows(inc).Item(1) = txtRefNumber.Text
ds.Tables("Inventory").Rows(inc).Item(2) = txtCategory.Text
ds.Tables("Inventory").Rows(inc).Item(3) = txtQuantity.Text
ds.Tables("Inventory").Rows(inc).Item(5) = txtLotNumber.Text

da.Update(ds, "Inventory")

MsgBox("Data updated")
End Sub

Im able to run my Form, just when I want to update the changes made into the field "Lot Number" I get the same error.

Any help?










privacy (GDPR)