存儲過程的定義
CREATE procedure pro_buyGoods
(
@GoodsName varchar(
@GoodsNum int
)
AS
declare @count as int
set @count = (select count(*) from T_Goods where GoodsName=@GoodsName)
if @count<=
insert into T_Goods values (@GoodsName
end
else begin
update T_Goods set GoodsNum=GoodsNum+@GoodsNum where GoodsName=@GoodsName
end
GO
說明
這是在ASP
int BuyGoodsID = Convert
string GoodsName = this
int GoodsNum = Convert
int GoodsPrice = Convert
SqlConnection conn = DB
conn
string cmdText =
SqlCommand cmd = new SqlCommand(cmdText
SqlTransaction trans = conn
cmd
try
{
cmd
//插入庫存表的代碼
SqlCommand cmd
cmd
cmd
cmd
cmd
cmd
cmd
cmd
cmd
this
this
this
trans
}
catch(Exception exp)
{
trans
Response
}
finally
{
conn
}
***********************************************************************
set @count = (select count(*) from T_Goods where GoodsName=@GoodsName)
改為
select @count = count(*) from T_Goods where GoodsName=@GoodsName
From:http://tw.wingwit.com/Article/program/net/201311/12336.html