Question Syntax error in UPDATE statement

ssgglenn

Member
Joined
Jul 14, 2008
Messages
11
Programming Experience
1-3
I am trying to save a record in a dataset and keep getting a message that there's a syntax error in the UPDATE statement. I am new to coding so I have no idea what this error is.

The following code is in the Windows form designer code area:

me.OleDbUpdateCommand1.CommandText = "UPDATE Soldiers SET AKOEmail = ?, CellPhone = ?, City = ?, First = ?, Last = ?, L" & _
"ast4 = ?, MOS = ?, PrimaryEmail = ?, Rank = ?, SoldierID = ?, State = ?, Street1" & _
" = ?, Street2 = ?, Zip = ? WHERE (SoldierID = ?)"
Me.OleDbUpdateCommand1.Connection = Me.odcSoldiers
Me.OleDbUpdateCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("AKOEmail", System.Data.OleDb.OleDbType.VarWChar, 50, "AKOEmail"))
Me.OleDbUpdateCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("CellPhone", System.Data.OleDb.OleDbType.VarWChar, 50, "CellPhone"))
Me.OleDbUpdateCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("City", System.Data.OleDb.OleDbType.VarWChar, 50, "City"))
Me.OleDbUpdateCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("First", System.Data.OleDb.OleDbType.VarWChar, 30, "First"))
Me.OleDbUpdateCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("Last", System.Data.OleDb.OleDbType.VarWChar, 30, "Last"))
Me.OleDbUpdateCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("Last4", System.Data.OleDb.OleDbType.SmallInt, 0, "Last4"))
Me.OleDbUpdateCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("MOS", System.Data.OleDb.OleDbType.VarWChar, 10, "MOS"))
Me.OleDbUpdateCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("PrimaryEmail", System.Data.OleDb.OleDbType.VarWChar, 50, "PrimaryEmail"))
Me.OleDbUpdateCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("Rank", System.Data.OleDb.OleDbType.VarWChar, 3, "Rank"))
Me.OleDbUpdateCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("SoldierID", System.Data.OleDb.OleDbType.VarWChar, 7, "SoldierID"))
Me.OleDbUpdateCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("State", System.Data.OleDb.OleDbType.VarWChar, 2, "State"))
Me.OleDbUpdateCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("Street1", System.Data.OleDb.OleDbType.VarWChar, 50, "Street1"))
Me.OleDbUpdateCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("Street2", System.Data.OleDb.OleDbType.VarWChar, 50, "Street2"))
Me.OleDbUpdateCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("Zip", System.Data.OleDb.OleDbType.VarWChar, 50, "Zip"))
Me.OleDbUpdateCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("Original_SoldierID", System.Data.OleDb.OleDbType.VarWChar, 7, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "SoldierID", System.Data.DataRowVersion.Original, Nothing))


and the following is the procedure I have written for the save command


Private Sub SaveRecord()

Try
Me.BindingContext(Me.dsSoldiers, "soldiers").EndCurrentEdit()
Me.odaSoldiers.Update(Me.dsSoldiers, "soldiers")
Catch eSave As Exception
MessageBox.Show(eSave.Message)
End Try
Me.dsSoldiers_PositionChanged()
ReadOnlyOn()

End Sub

Can any tell me what I am missing here?

Thanks
 
This is often a symptom of using a reserved word as an identifier. Try wrapping any suspicious column names in brackets []. For instance, PrimaryEmail is certainly alright but Rank might be an issue.
 
Back
Top