Recently I was working on a small application that required writing to a local Microsoft Access database. This was done using Microsoft C# .NET 3.5 (SP1) but every time I clicked the submit button on the relevant form I received an error message saying there was a syntax error in the INSERT INTO statement. Here’s how to fix this error …
For a start, the INSERT statement’s syntax was perfectly fine – I tested it using a new query from within Microsoft Access. The fields in question were called ‘email’ and ‘identifier’ and it turned ‘email’ is a reserved word in Microsoft Access. One of the original SQL statements looked something like this:
That is one of the statements that caused the error. Because of the Microsoft Access reserved words you must enclose the column names in square brackets, like this:
Enclosing the column names in square brackets is apparently best practice anyway (as found in many MS SQL Server queries) but nonetheless … problem solved!
Dude u just saved my Life! i was trying to do this four hours man! i searched and searched and studied soo much from ebooks but to no avail. i am doin my project and compatibility issues required that i use ACCESS and everything from CommandBuilders to Insertcommands was giving errors..was finally gonna work on SQL but for this last moment find. thanx Buddy!. All d Best to u in Life!
Thanks! Saved what little hair I have left!
Thanks for posting this information. I was also getting same error
chandradev: No problem, I’m glad the information helped you – it was a pain when I got the error too.
Wow its just funny.Yesterday evening my wife had the same problem and she asked me to help her.I tried but couldn’t find the issue.Now tried it worked.Thanks Buddy.God bless you.
Regards,
Zainu
Thank you so much.
I also had the same problem and Im breaking my head for 2 days. Your solution resolved my problem. Thank you
This has saved me tons of work, thanks for posting and ranking for this on google!
johnny