Access SQL syntax error when using OleDbCommandBuilder

后端 未结 1 1500
一个人的身影
一个人的身影 2020-12-01 20:07

I am going to INSERT data in Access Database using OleDbDataAdapter in C# but i got an error with message Syntax Error in INSERT INTO Command



        
相关标签:
1条回答
  • 2020-12-01 21:04

    Try this:

    Immediately after the line

    var builder = new OleDbCommandBuilder(dbAdapter);
    

    add the two lines

    builder.QuotePrefix = "[";
    builder.QuoteSuffix = "]";
    

    That will tell the OleDbCommandBuilder to wrap table and column names in square brackets, producing an INSERT command like

    INSERT INTO [TableName] ...
    

    instead of the default form

    INSERT INTO TableName ...
    

    The square brackets are required if any table or column names contain spaces or "funny" characters, or if they happen to be reserved words in Access SQL. (In your case, I suspect that your table has a column named [Password], and PASSWORD is a reserved word in Access SQL.)

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