asp.net 读取sql存储过程返回值

关于Exec返回值的问题有很多,在这做个简要的总结。
   
   读查询语句示例:
     Declare @count int

1    set @strSql=N'select @a= count(*) from ['+ @tblName + '] where  1=1 '+   @strWhere
2    exec sp_executesql  @strSql ,N'@a int output',@Count output
3    select @Count

    
   要点:
                        1.利用系统存储过程 sp_executesql
                        2. 在要执行的Sql文中加入参数,如 "@a",在sp_executesql的参数  声 明中要指定参数的类型,参数的方向。
                        3. sp_executesql的每个字符类型的参数都要是 n开头的数据类型,如是nvarchar 不能是      varchar,否则会报错“过程需要类型为 'ntext/nchar/nvarchar' 的参数”.

         读存储过程示例:

create procedure ProTest
(
         
@name varchar(10),
         
@money int output
)
as
begin
        
if(@name='1')
                  
set @money=1000
        
else
                  
set @money=2000
end


这个只是一个简单的示例,这个存储过程返回的是@money 这个参数的值,那么当我们在另外一个存储过程中调用此存储过程的时候如何获取这个参数呢,方法如下:

declare @m int ---用来接收返回值的变量
exec ProTest @name='1',@money=@m output --一定要注名是output
原文地址:https://www.cnblogs.com/wwy224y/p/3619738.html