首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

在存储过程中,怎么返回值

2012-01-16 
在存储过程中,如何返回值....EXEC (DELETE trainWHERE train_id IN ( + @selecteds + ))如果我加上ret

在存储过程中,如何返回值
....
EXEC ('DELETE train WHERE train_id IN (' + @selecteds + ')')
如果我加上return 1则提示:在此上下文中不能使用带有返回值的 RETURN 语句
我主要是想这样:删除成功时,则返回为1,否则为-1


[解决办法]
比如存贮过程为 tmp2,用@i来接收返回值

declare @i int
exec @i=tmp2
[解决办法]
使用存储过程返回值
例1

SQL code
create procedure testasselect 1declare @i intexec @i = test
[解决办法]
方法有很多种的

1、可以利用 output 参数
 SqlParameter 的 Dicection 属性要设置为输出类型
Dim parameter As New SqlParameter("Description", SqlDbType.VarChar, 88)
parameter.Direction = ParameterDirection.Output

  
2、可以用 return 返回值
SqlParameter 的 Dicection 属性要设置为返回值类型
parameter.Direction = ParameterDirection.ReturnValue

3、如果返回表,可以直接 运行select 语句
然后执行 SqlCommand.ExecuteReader 返回表

热点排行