...

View Full Version : Syntax error in UPDATE statement



cbowen2
07-26-2005, 02:36 PM
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

Brandoe85
07-26-2005, 08:31 PM
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 :)

cbowen2
07-26-2005, 09:36 PM
You are a life saver, thank you very much!

sirjoshua00
02-17-2011, 04:24 PM
thank you Brando

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

geraldmaybe
03-09-2011, 10:48 AM
Thanx ! really this is a big problem.very thanx.


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

pipelian
04-26-2011, 04:49 AM
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?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum