Reputation: 21
im programming a "Change password" Form on VB.net. This is the code of OK Button:
Private Sub BT_CambiaPass_OK_Click(sender As Object, e As EventArgs) Handles BT_CambiaPass_OK.Click
Dim strSql As String = "UPDATE Usuario SET Password= ? WHERE NombreUsuario= ? AND Password= ?"
Using cmd As New OleDb.OleDbCommand(strSql, conexion)
cmd.Parameters.AddWithValue("Password_New", CStr(TB_CambiaPass_NEW.Text))
cmd.Parameters.AddWithValue("NombreUsuario", CStr(NombreUsuario))
cmd.Parameters.AddWithValue("Password_Old", CStr(TB_CambiaPass_Old.Text))
Try
conectarse()
cmd.ExecuteNonQuery()
conexion.Close()
Catch ex As Exception
MsgBox("Contraseña antigua incorrecta")
MsgBox(ex.ToString())
End Try
End Using
End Sub
The ex.tostring return "Syntax error on instruction UPDATE...", when debug the variables are OK, but where executeNonQuery get this error.
I have anothers functions like this and they run ok. In fact I tryed the SQL instruction "UPDATE Usuario SET Password= "123" WHERE NombreUsuario= "Admin" AND Password= admin" in Access and all goes OK.
I dunno what's wrong...
Sorry about my primitive english!
Upvotes: 0
Views: 62
Reputation: 81610
Password is a keyword, so you have to put it in brackets:
... "UPDATE Usuario SET [Password]= ? WHERE NombreUsuario= ? AND [Password]= ?"
Upvotes: 1