【发布时间】:2014-01-31 16:48:50
【问题描述】:
我是 SQL 和 C# 的新手,我遇到了这个 SQL 错误。
参数化查询 '(@pid nvarchar(4000),@desc nvarchar(4000),@cat nvarchar(4000),@p' 需要参数'@pid', 没有提供。
我真的需要帮助。谢谢!
public void InsertRecord()
{
SqlCommand cmd = new SqlCommand("INSERT INTO PRODUCTS VALUES (@pid, @desc, @cat, @price, @scode)", myCon);
cmd.Parameters.AddWithValue("@pid", productID);
cmd.Parameters.AddWithValue("@desc", description);
cmd.Parameters.AddWithValue("@cat", category);
cmd.Parameters.AddWithValue("@price", price);
cmd.Parameters.AddWithValue("@scode", supplierCode);//corrected the "key codes"
myCon.Open();
cmd.ExecuteNonQuery();
myCon.Close();//added these lines of codes
}
【问题讨论】:
-
productID 是否为空?
-
您使用的 INSERT 语法要求传递所有字段值以进行插入,您的表 PRODUCTS 中是否只有 5 个字段?
-
我无法启用 productID 文本框。我不知道为什么。
-
我的意思是文本框已启用,但我无法在其中输入任何内容。
-
C# 中的 Windows 窗体应用程序