Search code examples
sqlsyntaxmdf

incorrect syntax error near ,


I have recently changed my database from access to a .mdf and now I am having problems getting my code to work.

One of the problems im having is this error "incorrect syntax near ,".

I have tried different ways to try fix this for example putting brackets in, moving the comma, putting spaces in, taking spaces out but I just cant get it.

I would be so grateful if anyone could help me.

My code is:

SqlStr = "INSERT INTO UserTimeStamp ('username', 'id') SELECT ('username', 'id') FROM Staff WHERE password = '" & passwordTB.Text & "'"

Solution

  • Assuming you're looking for username and id columns, then that's not proper SQL syntax.

    The main issues are that you're column names are enclosed in single quotes and in parentheses in your select. Try changing it to this:

    SqlStr = "INSERT INTO UserTimeStamp (username, id) SELECT username, id FROM Staff WHERE password = '" & passwordTB.Text & "'"
    

    That will get sent off to SQL like this:

    INSERT INTO UserTimeStamp (username, id) 
        SELECT username, id 
        FROM Staff
        WHERE password = 'some password'