--用ParameterDirection.ReturnValue; 返回值
CREATE PROCEDURE dbo.a
AS
declare @i int
select @i=count(*) from tbD_M_Modle
return @i
GO
--用ParameterDirection.Output; 参数返回值
CREATE PROCEDURE dbo.a
@i int output
AS
select @i=count(*) from tbD_M_Modle
return @i
GO
//
SqlCommand cmd = new SqlCommand("a", myConn);
cmd.CommandType = CommandType.StoredProcedure;
//输入值
//SqlParameter a1 = new SqlParameter("@a", SqlDbType.VarChar, 100);
//a1.Value="aaa";
//cmd.Parameters.Add(a1);
//返回值
SqlParameter i = new SqlParameter("@ii", SqlDbType.Int,4);
i.Direction = ParameterDirection.Output;
//i.Direction = ParameterDirection.ReturnValue;
cmd.Parameters.Add(i);
cmd.ExecuteNonQuery();
string strReturn = i.Value.ToString(); //返回值--方法1
string a = cmd.Parameters["@ii"].Value.ToString(); ////返回值--方法2
cmd.Connection.Close();