C# 接受存储过程返回值 和 output 返回值
try { int iCnt = -1; int iTest = -1; SqlParameter[] para = { new SqlParameter("@col1",10), new SqlParameter("@col2",'Z'), new SqlParameter("@cnt",iCnt), new SqlParameter("@test",iTest) }; para[2].Direction = ParameterDirection.Output;//这里接受的是output的值 para[3].Direction = ParameterDirection.ReturnValue;//这里接收的是return 的值 SqlHelper.ExecuteNonQuery(sConn, CommandType.StoredProcedure, "p_tab", para); string str1 = para[2].Value.ToString(); string str2 = para[3].Value.ToString(); } catch (Exception ex) { throw ex; }
ALTER proc [dbo].[p_tab]@col1 int ,@col2 varchar(20),@cnt int outputasbegin insert into Tab values(@col1,@col2) select @cnt= COUNT(1) from Tab declare @test int set @test=55 return @testend