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

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: http://support.microsoft.com/kb/321266/en-us

Ned Sahin

Blogger for 20 years. Former Microsoft Engineer. Author of six books. I love creating helpful content and sharing with the world. Reach me out for any questions or feedback.

Leave a Comment