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? :/

Recommended Answers

All 5 Replies

Try removing the semicolon.

Hi,

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 & "';"

And, of course, you should be using parameterized queries. See example here

Can you post the error message you received ? It will help us to figure out the problem.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.