Syntax Error

Recently I was working on a client’s project in C# with MS Access database. I usually don’t work on windows-only tools so it was somewhat of a learning experience. Anyways, while working on the project, we got stuck on a query.

It was an INSERT query which was running perfectly fine in Access, but when executed through C# it gave syntax error. Values were populating just fine, quotes were in right places but it continued to give syntax error, while copying it and running it in Access worked fine. After wasting couple of hours, we finally found out that problem was with fieldnames, apparently one of the fieldname was causing some problem, and we had to enclose each field name in square brackets [] to make them work.

So, if you are stuck in such a situation, try enclosing fieldnames in square brackets, actually it is usually considered a good practice to always enclose fieldnames in square brackets in MS Access queries.

One thought on “Syntax Error

  1. Assalam o ALikum

    yes Aqeel you are right, this problem arises while using Access database, I have used OleDb, ADO.NET, SQL native client, but the problem remains while working with access database…

    Regards,
    H R Abbasi

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>