You need to configure SqlConnection and SqlCommand . If you have code with the RETURN @Sum operator at the end, you need to do this (define a parameter of type RETURN_VALUE):
using(SqlConnection _conn = new SqlConnection(-your-connection-string-here)) using(SqlCommand _cmd = new SqlCommand("dbo.sp_Noskheh_SumOfTotalPay", _conn)) { _cmd.CommandType = CommandType.StoredProcedure; _cmd.Parameters.Add(new SqlParameter("@CO_ID", SqlDbType.Int)); _cmd.Parameters["@CO_ID"].Value = 5;
It would be much simpler if you replace this RETURN statement with a simple SELECT:
SELECT @Sum
In this case, you can use the simplified version that I had before - using .ExecuteScalar() to get the only value of one line returned from the stored proc:
using(SqlConnection _conn = new SqlConnection(-your-connection-string-here)) using(SqlCommand _cmd = new SqlCommand("dbo.sp_Noskheh_SumOfTotalPay", _conn)) { _cmd.CommandType = CommandType.StoredProcedure; _cmd.Parameters.Add(new SqlParameter("@CO_ID", SqlDbType.Int)); _cmd.Parameters["@CO_ID"].Value = 5;
This should call your saved proc, read the one value you return, and convert it to an int variable called sum .
source share