--用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();
--用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();