【问题标题】:INSERT INTO Syntax error c#,AccessINSERT INTO 语法错误 c#,Access
【发布时间】:2016-07-12 20:17:51
【问题描述】:

我在查询中收到“INSERT INTO 语法错误”,我不知道为什么。 (与 Access 的连接在另一个类中)。

    public void InsertOrder(Order Item) // add new order
    {
        string cmdStr = "INSERT INTO [Order] (CostumerID,ProID,ProName,ProPrice,Comments,Discount,Color,Size,Quantity,OrdertDate) VALUES (@costumerID,@proID,@proName,@proPrice,@comments,@discount,@proColor,@proSize,@quantity,@orderDate)";
        using (OleDbCommand command = new OleDbCommand(cmdStr))
        {

            command.Parameters.AddWithValue("@costumerID", Item.CostumerID);
            command.Parameters.AddWithValue("@proID", Item.ProId);
            command.Parameters.AddWithValue("@proName", Item.ProName);
            command.Parameters.AddWithValue("@proPrice", Item.ProPrice);
            command.Parameters.AddWithValue("@comments", Item.Comments);
            command.Parameters.AddWithValue("@discount", Item.Discount);
            command.Parameters.AddWithValue("@proColor", Item.ProColor);
            command.Parameters.AddWithValue("@proSize", Item.ProSize);
            command.Parameters.AddWithValue("@quantity", Item.Quantity);
            command.Parameters.AddWithValue("@orderDate", Item.OrderDate);

            base.ExecuteSimpleQuery(command);
        }

    }

有什么帮助吗? 谢谢!

【问题讨论】:

  • 您已提出 8 个问题并得到 11 个答案,但没有一个接受。正如Tour 中所解释的,接受答案和(稍后)投票可以帮助其他用户找到好的答案。请花点时间拨打Tour 并单击您过去获得的一些答案上的复选标记。

标签: c# sql ms-access


【解决方案1】:

你需要看看这个页面:Reserved Words in MSAccess

您会注意到 SIZE 是保留关键字,因此如果您确实无法更改该名称并仍想在代码中使用它,则需要将其括在方括号中

   string cmdStr = @"INSERT INTO [Order] 
          (CostumerID,ProID,ProName,ProPrice,Comments,
           Discount,Color,[Size],Quantity,OrdertDate) 
           VALUES (@costumerID,@proID,@proName,@proPrice,@comments,
                   @discount,@proColor,@proSize,@quantity,@orderDate)";

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-02-07
  • 1970-01-01
  • 1970-01-01
  • 2011-10-04
  • 1970-01-01
相关资源
最近更新 更多