首页 > 代码库 > 存储过程简单调用(from www.sysoft.cc)

存储过程简单调用(from www.sysoft.cc)

建立存储过程:

set ANSI_NULLS ONset QUOTED_IDENTIFIER ONgoALTER proc [dbo].[likefilm]@uid int,@fid int,@error int,@result int outputasbegin transactionupdate dbo.Film set LikeCount=LikeCount+1 where Id=@fiddeclare @likeid nvarchar(500)set @likeid=(select LikeId from dbo.Users where Id=@uid)if(@likeid=0)beginupdate dbo.Users set LikeId=cast(@fid as nvarchar(50))+| where id=@uidendelsebeginupdate dbo.Users set LikeId=cast(@fid as nvarchar(50))+|+LikeId where id=@uidendset @result=1set @error=@error+@@errorif(@error>0)begin rollback transactionendelsebegin  commit transactionend

调用存储过程

 

 SqlParameter error = new SqlParameter("error", 0);                        SqlParameter Uid = new SqlParameter("uid", Convert.ToInt32(uid));                        SqlParameter Fid = new SqlParameter("fid", Convert.ToInt32(fid));                        SqlParameter Resault = new SqlParameter("result", 0);                        Resault.Direction = System.Data.ParameterDirection.Output;                        SqlParameter[] pms = new SqlParameter[] {Uid,Fid,Resault,error};                        int resault=0;                        DbHelperSQL.RunProcedure("likefilm", pms, out  resault);

 

存储过程简单调用(from www.sysoft.cc)