Solved: “Syntax error in INSERT INTO statement” error that shows up when you connect Access via C#/SQL

Inserting date/time string to database via SQL is generally problematic. Your interpreter (which is Visual Studio in my case) might show up this error:

“Syntax error in INSERT INTO statement”

Solution is adding wrapping square brackets around date (because date is a reserved word) and # signs around the string (it points out the date) like you will see below:

cmd.CommandText = "INSERT INTO AlarmHistory ([Date]) VALUES (#6/8/2012#)";

If It still doesn’t work, check your Access settings. Here is convenient settings for my example:

Settings on Access table

Check the reserved words for Microsoft Jet 4.0:

Who Unfriended me on Facebook?

Spread the word!

Leave a Reply

Your email address will not be published. Required fields are marked *