I'm trying to do my Computing coursework, and every time I try to write an UPDATE statement in SQL, it tells me there is a syntax error in the statement. The connection is set up, I know, as other SQL statements like select statements work, but I can't work out what is wrong. Here's the code:

newpass = newpassword1.Text
passwordchange = "UPDATE Student SET Password = '" & newpass & "' WHERE Username = '" & username & "';"

All of table and field names are correct and in the right format etc. and newpass and username both read in string values.

Any ideas? :/

Edited by pritaeas: Added code tags

5 Years
Discussion Span
Last Post by ShahanDev


Have you tried running in debug and doing watches on newpass and passwordchange?

Maybe newpassword1.text is empty?

Also how are you running the passwordchange query through a sql command? could you show us the code where yu execute the query?


Password is a reserved word. Try

passwordchange = "UPDATE Student SET [Password] = '" & newpass & "' WHERE Username = '" & username & "';"
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.