I have an SQL Server Stored Procedure
. This procedure have an output parameter.
On my C#.NET
Appliaction, I execute this procedure via SqlHelper.ExecuteDataSet()
and it returns a query result DataSet
.
How can I get the output parameter from the stored procedure procedure while using SqlHelper.ExecuteDataSet()
.
Some article said that I need to use SqlHelper.ExecuteNonQuery()
but I need the DataSet
too.
This is my code:
public DataSet GetDataPerTable(string spName, string a, string b, out int c)
{
try
{
c = 0;
SqlParameter[] spParameter = new SqlParameter[3];
spParameter[0] = new SqlParameter("@a", SqlDbType.Char, 4);
spParameter[0].Direction = ParameterDirection.Input;
spParameter[0].Value = a;
spParameter[1] = new SqlParameter("@b", SqlDbType.Char, 1);
spParameter[1].Direction = ParameterDirection.Input;
spParameter[1].Value = b;
spParameter[2] = new SqlParameter("@c", SqlDbType.Int);
spParameter[2].Direction = ParameterDirection.ReturnValue;
c = Convert.ToInt32(spParameter[2].Value);
return SqlHelper.ExecuteDataset(Configuration.MyConnectionString, CommandType.StoredProcedure, spName, spParameter);
}
catch (Exception ex)
{
throw ex;
}
}
My c
variable always return 0. Any Idea? Thanks in advance :)
My Procedure is about like this:
CREATE PROCEDURE [dbo].SPR_MyProcedure (@a Char(4), @bChar(1), @c Int Output)
SELECT *
FROM MyTable
Set @c = 1