MS Access – Syntax error in INSERT INTO statement.

If you receive this error while working within the Visual Studio environment and  you are trying to append a record into an MS Access database, there could be a number of reasons that you are getting this error.  The reason I was receiving this error and quite frankly a rather frustrating reason at that was because of one of my field names, password.

I should know better than to give database field names that are reserved words or potentially reserved words, but since I was creating this app anticipating newbie programmers would take it over, I wanted to be as descriptive and unambiguous as possible.

So anyway, the following insert statement in Visual Studio failed when I went to update my database.

INSERT INTO users (username, password, first_name, last_name) VALUES ('jd', 'turk', 'John', 'Dorian');

I received the error: Syntax error in INSERT INTO statement.

What needed to be done here is enclose the field name “password” in brackets [].  So the statement should read:

INSERT INTO users (username, [password], first_name, last_name) VALUES ('jd', 'turk', 'John', 'Dorian');

Although the first query will work if you execute it within the MS Access environment, it will not work if you execute it within the code in your Visual Studio program.

Questions, comments and contributions are welcomed.

Advertisement

2 Comments

Filed under Sharing Stuff

2 Responses to MS Access – Syntax error in INSERT INTO statement.

  1. Bikram

    Thanks…It did solved my issue. I was using TimeStamp as my column name. Changing it solved my error.

  2. aloka

    You are my lucky star…
    I have been worked out for 24hours to find out the problems…
    Just because BRACKET!!!!

Comment on this

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s