尝试将数据添加到数据库时,我收到以下内容。
附加信息:INSERT INTO语句中的语法错误。
任何人都可以帮助PLZ吗?谢谢
cmd.CommandText = "INSERT INTO [Order History] ([Order ID], [Item ID], [Items Sold], [Cases on hold], [Cases suggested to order], [Cases Ordered]) VALUES (@id, @iId, @iSold, @cHold, @csOrder, @cOrdered)"
cmd.Parameters.AddWithValue("@id", txtOrderID.Text)
cmd.Parameters.AddWithValue("@iId", txtItemID.Text)
cmd.Parameters.AddWithValue("@iSold", txtItemsSold.Text)
cmd.Parameters.AddWithValue("@cHold", txtCasesonhold.Text)
cmd.Parameters.AddWithValue("@csOrder", txtCasessuggestedtoorder.Text)
cmd.Parameters.AddWithValue("@cOrdered", txtCasesOrdered.Text)
cmd.ExecuteNonQuery()
答案 0 :(得分:0)
假设您正在使用System.Data.OleDbCommand
对象,请尝试:
cmd.CommandText = "INSERT INTO [Order History] ([Order ID], [Item ID], [Items Sold], [Cases on hold], [Cases suggested to order], [Cases Ordered]) VALUES (?, ?, ?, ?, ?, ?)"
cmd.Parameters.AddWithValue("@id", txtOrderID.Text)
cmd.Parameters.AddWithValue("@iId", txtItemID.Text)
cmd.Parameters.AddWithValue("@iSold", txtItemsSold.Text)
cmd.Parameters.AddWithValue("@cHold", txtCasesonhold.Text)
cmd.Parameters.AddWithValue("@csOrder", txtCasessuggestedtoorder.Text)
cmd.Parameters.AddWithValue("@cOrdered", txtCasesOrdered.Text)
cmd.ExecuteNonQuery()
OLE DB .NET提供程序不支持将参数传递给SQL语句的命名参数。必须使用问号(?)占位符。看到: http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbcommand.parameters.aspx