存储过程
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER proc [dbo].[memberproductInsert]
@Name varchar(50),
@TypeID varchar(50),
@KeyWord nvarchar(40),
@Picture nvarchar(100),
@Detail text,
@AddDate datetime,
@Price float,
@UserID int,
@Verify int,
@Sort int,
@Ask varchar(100),
@IsTop bit,
@LastDate datetime,
@Money float
AS
Begin
begin transaction AddproductInfo
declare @ID int
insert into w_products ([Name],TypeID,KeyWord,Picture,Detail,AddDate,Price) values(@Name,@TypeID,@KeyWord,@Picture,@Detail,@AddDate,@Price)
set @ID = scope_identity()
insert into w_usersproducts (UserID,ProductID,Verify,Sort,AddDate,Ask,IsTop,LastDate,[Money]) values(@UserID,@ID,@Verify,@Sort,@AddDate,@Ask,@IsTop,@LastDate,@Money)
if @@Error<>0
begin
Rollback transaction AddproductInfo
end
commit transaction AddproductInfo
End
调用存储过程方法
public int memeberProInsert(memeberProduct pro)
{
SqlParameter[] commentParameter = new SqlParameter[]
{
new SqlParameter("@name",pro.Name),
new SqlParameter("@TypeID",pro.TypeId),
new SqlParameter("@KeyWord",pro.KeyWord),
new SqlParameter("@Picture",pro.Picture),
new SqlParameter("@Detail",pro.Detail),
new SqlParameter("@AddDate",pro.AddDate),
new SqlParameter("@Price",pro.Price),
new SqlParameter("@UserID",pro.UserId),
new SqlParameter("@Verify",pro.Verify),
new SqlParameter("@Sort",pro.Sort),
new SqlParameter("@Ask",pro.Ask),
new SqlParameter("@IsTop",pro.IsTop),
new SqlParameter("@LastDate",pro.LastDate),
new SqlParameter("@Money",pro.Money)
};
return SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "memberproductInsert", commentParameter);
}