Is it possible to use dataBase.executeNonQuery and use a return value from a stored proc?

148 views Asked by At

I have done some research and found a few ideas on how we can use a return value from a stored proc like:

using (SqlCommand cmd = conn.CreateCommand())
{
    cmd.CommandText = parameterStatement.getQuery();
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.Parameters.AddWithValue("SeqName", "SeqNameValue");

    var returnParameter = cmd.Parameters.Add("@ReturnVal", SqlDbType.Int);
    returnParameter.Direction = ParameterDirection.ReturnValue;

    conn.Open();
    cmd.ExecuteNonQuery();
    var result = returnParameter.Value;
}

but i am using something like this:

Database.AddInParameter();

where i do not have to open and close connections..

Can some body help me to understand if it is possible to use Direction.Returnvalue using DataBase approach?

Sorry for a bit un-organized question :) please feel free to ask if anything is not clear

1

There are 1 answers

0
Saruchi On

use database.outParameter for parameters that return value