sql 存储过程返回值 C#

来源:百度知道 编辑:UC知道 时间:2024/05/12 00:02:48
存储过程如下:
create procedure gp_findtemptable
@v_userid varchar(50),
@i_out int out
as
declare @v_sql varchar(100)
if object_id('tempdb.dbo.##'+@v_userid) is null
begin
set @v_sql = 'create table ##'+@v_userid+'(userid varchar(50))'
exec (@v_sql)
set @i_out = 0
end
else
set @i_out = 1

GO
怎么样写C#语句把out取出来啊!

SqlParameter[] param={new SqlParameter("@i_out",...};

【param[0].Direction=ParameterDirection.OutPut;】

cmd.Execute...

param[0].value; //有返回值了。

也就是将param设置为输出参数, 执行完存储过程,param里面就有你的返回值了。

存储过程里的parm,设置方向为output
执行好,在关闭前
parm.value 就是所得