使用添加为值的参数执行此查询时,出现错误,提示我的语法错误。我尝试了以下多个教程,在这里查找问题是堆栈溢出,并且进行比较时,它们似乎相同,但是我的似乎不起作用。OleDbConnection con = new OleDbConnection(); con.ConnectionString = "Provider = Microsoft.ACE.OLEDB.12.0; Data Source =C:\\Users\\fidyc\\OneDrive\\Desktop\\ProgrII.accdb"; OleDbCommand cmd = new OleDbCommand("INSERT Product_Orders(order_ID,plankCount,thickness,width,height)VALUES(@order_ID, @plankCount, @thickness, @width, @height)"); cmd.Parameters.Add("@order_ID", OleDbType.Integer).Value = orderID; cmd.Parameters.Add("@plankCount", OleDbType.Decimal).Value = plankCount; cmd.Parameters.Add("@thickness", OleDbType.Decimal).Value = thickness; cmd.Parameters.Add("@width", OleDbType.Decimal).Value = width; cmd.Parameters.Add("@height", OleDbType.Decimal).Value = height; cmd.Connection = con; con.Open(); if (con.State == ConnectionState.Open) { /*try {*/ cmd.ExecuteNonQuery(); MessageBox.Show("Data Added"); con.Close(); /*} catch (OleDbException ex) { MessageBox.Show(ex.Source); con.Close(); }*/ }编辑:值传递给函数public static void Push(int orderID, decimal plankCount, decimal thickness, decimal width, decimal height) {
2 回答
慕田峪9158850
TA贡献1794条经验 获得超7个赞
问题原来是count列名,因为sql有一个count命令,所以它必须是
OleDbCommand cmd = new OleDbCommand("INSERT INTO Product_Orders(order_ID,[count],thickness,width,height)VALUES(@order_ID, @count, @thickness, @width, @height)");
代替
OleDbCommand cmd = new OleDbCommand("INSERT INTO Product_Orders(order_ID,count,thickness,width,height)VALUES(@order_ID, @count, @thickness, @width, @height)");
慕桂英4014372
TA贡献1871条经验 获得超13个赞
using (OleDbCommand cmd = conn.CreateCommand())
{
cmd.CommandText =
"INSERT INTO bookRated "+
"([firstName], [lastName]) "+
"VALUES(@firstName, @lastName)";
cmd.Parameters.AddRange(new OleDbParameter[]
{
new OleDbParameter("@firstName", firstName),
new OleDbParameter("@lastName", lastName),
});
cmd.ExecuteNonQuery();
}
- 2 回答
- 0 关注
- 239 浏览
添加回答
举报
0/150
提交
取消