求助!!存储过程出错!
set ANSI_NULLS ONset QUOTED_IDENTIFIER ON
go
ALTER PROCEDURE [dbo].[AddProduct]
@ProductName varchar(20),
@Category char(20),
@ProductRate money,
@Brand char(20),
@ProductQoh smallint,
@ProductImgPath varchar(50),
@ProductDescription varchar(250),
@CategoryId int, -- 为局部变量(不会声明)
@BrandId int -- 为局部变量
AS
select @CategoryId=(select cCategoryId from Category where cCategoryName=@Category)
select @BrandId=(select cBrandId from BrandId where cBrandName=@Brand)
BEGIN
SET NOCOUNT ON;
Insert into Product(vProductName,cCategoryId,mProductRate,cBrandId,siProductQoh,vProductImgPath,vProductDescription)
values(@ProductName,@CategoryId ,@ProductRate,@BrandId,@ProductQoh,@ProductImgPath,@ProductDescription)
END
语言是c#,是这样传递的
string sql = string.Format("AddProduct'{0}','{1}','{2}','{3}','{4}','{5}','{6}'", pName, pPcategory, pRate, pBrand, pAmount, pImgPath, pDescription);
bc.ExecSQL(sql);
我自定了一个类bc ExecSQL方法是
public Boolean ExecSQL(string sQueryString)
{
SqlConnection conn = new SqlConnection("Server=localhost;database=MyShop;user id=sa;password=123456");
conn.Open();
SqlCommand comm = new SqlCommand(sQueryString, conn);
try
{
comm.ExecuteNonQuery();
conn.Close();
}
catch (System.Exception em)
{
conn.Close();
TetMessage = "连接数据库失败" + em.ToString();
return false;
}
return true;
}
在线等!!