I have a program where a user can update their Password by Entering their old password in a textbox, and entering their new password in a separate textbox.
An update query then updates the database with the new password.
Try
If tbOldPassword.Text <> "" Then
For Each Row In ds.Tables("sqlAddNewDetails").Rows
If Row.Item(0) = gblstrUserID Then
If Row.Item(1) = tbOldPassword.Text Then
If tbPassword.Text = tbRePassword.Text Then
'Updates the database
sqlUpdate = ("UPDATE Users SET Password = '" & tbPassword.Text & "' WHERE userID = " & Row.Item(0))
Dim cmd As New OleDbCommand(sqlUpdate, con)
cmd.ExecuteNonQuery()
MsgBox("Password successfully changed")
Else : MsgBox("The passwords are not the same")
End If
Else : MsgBox("Invalid old password")
End If
End If
Next
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
However, everytime the code gets to cmd.ExecuteNonQuery(), it throws up an error saying that there is a syntax error in the Update query. However, If I use this query in Microsoft Access, it works fine so the Update query itself is written correctly. What could be wrong?
Note: I am using an UPDATE query in another piece of code within the same Sub routine and it works there. Its something about this query.
Note Again: If I change the Update query to UPDATE Users SET EMAIL = ‘” & tbPassword.Text & “‘ WHERE userID = ” & Row.Item(0)” it works. Something about Password that throws that error.
Password is a keyword, so wrap it in square brackets as below,
UPDATE Users SET [Password] =.....