OleDbCommandBuilder creates SQL statements that result in “syntax error”

后端 未结 3 1557
太阳男子
太阳男子 2020-12-04 03:08

Can someone please explain why, when I click the \"Commit\" button, I get the error

Syntax error in INSERT INTO statement.

Here\

3条回答
  •  隐瞒了意图╮
    2020-12-04 03:41

    As Makita mentions, your problem stems from the fact that Position is a reserved word in Jet/ACE SQL. The solution is to add the following two lines of code after you create the OleDbCommandBuilder object:

    cb.QuotePrefix = "["
    cb.QuoteSuffix = "]"
    

    That will tell the OleDbCommandBuilder to generate SQL statements like this

    INSERT INTO [TA_OFFICER] ([FirstName], ...
    

    ...instead of

    INSERT INTO TA_OFFICER (FirstName, ...
    

    Wrapping the Position column name in those square brackets will tell the Jet database engine that it is a column name, not a keyword.

提交回复
热议问题