Hi I have a problem with my SQL UPDATE

It says here:
Syntax error in UPDATE statement.

Here's my code:

    Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEdit.Click





        Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEdit.Click


           Dim sqlupdate As String


            sqlupdate = "UPDATE usernames set password = '" & txtPass.Text & "', userlevel = '" & cboUserlvl.Text & "', user_lname = '" & txtLName.Text & "', user_fname = '" & txtFName.Text & "', gender = '" & cboGender.Text & "', position = '" & txtPosition.Text & "', contact = '" & txtContact.Text & "', address = '" & txtAdd.Text & "', email = '" & txtEmail.Text & "'  where username = '" & txtUser.Text & "'"


                    executesql(sqlupdate)
                    MsgBox("Successfully update the user profile!", MsgBoxStyle.Information Or MsgBoxStyle.Exclamation, "Successful")
                    clear()

                    End Sub

I checked my db. btw I'm using MS Access 2007 and VB 2010, I think I got the names right but can't seem to find where's my error..

table name : usernames
Column names: username, password, userlevel, user_lname, user_fname, gender, position, contact, address, email

:( can anyone help me please?

Edited 3 Years Ago by Ashenvale

Please display the value of sqlupdate (Debug.WriteLine would be good) and post the results here. And before someone else says it, you should be using parameterized values instead of just concatenating to create your query.

Edited 3 Years Ago by Reverend Jim

Hi,

Looking at your code, I can only see two possible reasons for a syntax error:

  1. You are passing strings in for every field you are updating, are all the fields in the database definately string types?
  2. txtUser.text is either blank or has a value that doesn't match to a record in the table. i.e. there is no matching record in the table to update.

There could be something else going on but thats all I can see so far. As Reverend Jim says bedugg the code and do a watch on sqlupdate. You could try copying the sql produced in sqlupdate into your access DB querybuilder (in SQL mode,) and see if it highlights any syntax errors.

This question has already been answered. Start a new discussion instead.