存储过程中可以定义输出变量,返回值,执行存储过程还能获得结果集。每个存储过程都有默认的返回值,默认值为0。下面我们分别看看在management studio中如何查看输出参数,返回值以及结果集,然后我们再在ASP.NET调用存储过程中如何获得输出参数,返回值以及结果集。
首先:在sql server management studio中查看输出参数,返回值以及结果集。本示例以Northwind数据库为例。
1
create proc Employee
2
@Rowcount int=0 output
3
as
4
begin
5
SELECT * FROM [Northwind].[dbo].[Employees]
6
set @Rowcount=@@ROWCOUNT
7
end

2

3

4

5

6

7

运行以上存储过程的代码如下:

可以看出是通过EXEC @return_value = [dbo].[Employee] @Rowcount = @MyOutput OUTPUT中的return_value变量来获得返回值,而用MyOutput变量来获得了输出变量值,此处的MyOutput变量相当于引用传递!
接下来将讨论ASP.NET调用存储过程中如何获得输出参数,返回值以及结果集。
