码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2014-11-19 20:20:29      阅读:213      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   ar   color   sp   on   div   

建立存储过程:

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go



ALTER proc [dbo].[likefilm]

@uid int,
@fid int,
@error int,
@result int output
as
begin transaction
update dbo.Film set LikeCount=LikeCount+1 where Id=@fid
declare @likeid nvarchar(500)
set @likeid=(select LikeId from dbo.Users where Id=@uid)

if(@likeid=0)
begin
update dbo.Users set LikeId=cast(@fid as nvarchar(50))+| where id=@uid
end
else
begin
update dbo.Users set LikeId=cast(@fid as nvarchar(50))+|+LikeId where id=@uid
end
set @result=1
set @error=@error+@@error
if(@error>0)
begin
 rollback transaction
end
else
begin
  commit transaction
end

调用存储过程

 

 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)

标签:style   blog   http   io   ar   color   sp   on   div   

原文地址:http://www.cnblogs.com/sysoft/p/4109007.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!