OleDbCommandBuilder creates SQL statements that result in “syntax error”

后端 未结 3 1555
太阳男子
太阳男子 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:36

    Position is a reserved word for JET 4.0 - try to rename the column something else such as prog_position. Access will often let you create the column with a reserved name, but when you go to access it in code JET blocks it and gives you a generic Syntax error in INSERT INTO Statement error without being specific. Check out http://support.microsoft.com/kb/248738 for more information on reserved words. It is goods practice to always prefix your column names with something short so that you never run into conflicts or reserved word issues.

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2020-12-04 03:53

    This kind of error can happen when you have different data type in the code and in the DB. Checking the log can give some light on this.

    0 讨论(0)
提交回复
热议问题