我试图从 C# winforms 应用程序简单地将数据插入到 SQL Server 中的表中。
目前在执行查询时我收到错误:
“soAddItems”附近的语法不正确
这是我insert
处理数据库 CRUD 操作的类的代码:
注:作为测试数据:
- itemName = "测试"
- skuNo = "a123"
- 商品价格 = 2.99
- stockItemToAdd = 3
- itemPic = "C:\Users\Name\Pictures\pic.png"**
代码:
public virtual void AddItem(string itemName, string skuNo, double itemPrice, int stockAmountToAdd, string itemPic)
{
using (SqlConnection open = new SqlConnection(connectionString))
{
SqlCommand insertCommand = new SqlCommand("soAddItems", open);
open.Open();
insertCommand.Parameters.Add("@itemName", SqlDbType.NChar).Value = itemName;
insertCommand.Parameters.Add("@skuNo", SqlDbType.VarChar).Value = skuNo;
insertCommand.Parameters.Add("@itemPrice", SqlDbType.Decimal).Value = itemPrice;
insertCommand.Parameters.Add("@instockAmount", SqlDbType.BigInt).Value = stockAmountToAdd;
insertCommand.Parameters.Add("@lastSold", SqlDbType.DateTime).Value = DateTime.Today;
insertCommand.Parameters.Add("@itemPic", SqlDbType.NChar).Value = itemPic;
//***** Error on the execute*****
insertCommand.ExecuteNonQuery();
};
}
SQL Server 存储过程:
ALTER PROC [dbo].[soAddItems]
@itemName nchar,
@skuNo varchar,
@itemPrice float,
@instockAmount bigint,
@lastSold dateTime,
@itemPic varchar
AS
BEGIN
INSERT INTO items (itemName, skuNo, itemPrice, instockAmount, lastSold, itemPic)
VALUES (@itemName, @skuNo, @itemPrice, @instockAmount, @itemPic)
END
谁能告诉我哪里出错了?