INSERT INTO语句中的语法错误(插入记录)

时间:2014-07-01 16:24:04

标签: sql database ms-access insert-into executenonquery

有人可以帮我解决我的代码有什么问题吗?它始终在INSERT INTO语句中说"语法错误。 "

try
        {

            OleDbConnection Con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\\MotoFix.mdb;");



            Con.Open();
            OleDbCommand Com = new OleDbCommand();

            Com.Connection = Con;
             Com.CommandText = "INSERT INTO Order VALUES ('" + txtRandomOrder.Text + "','" + txtCode.Text + "')";
              Com.ExecuteNonQuery();
             Con.Close();
        }
        catch (Exception ex)
        {
            XtraMessageBox.Show(ex.Message);
        }

1 个答案:

答案 0 :(得分:2)

订单是msaccess中的关键字,请参阅此链接

http://office.microsoft.com/en-us/access-help/access-2007-reserved-words-and-symbols-HA010030643.aspx

将您的陈述更改为

"INSERT INTO [Order] VALUES ('" + txtRandomOrder.Text + "','" + txtCode.Text + "')";

看看它是否有效