My code is as shown below :
using (SqlConnection _conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DarmanConnectionString"].ToString()))
{
using (SqlCommand _cmd = new SqlCommand("dbo.sp_Noskheh_SumOfTotalPay", _conn))
{
_cmd.CommandType = CommandType.StoredProcedure;
_cmd.Parameters.Add(new SqlParameter("@Co_ID", int.Parse(Session["Co_ID"].ToString())));
_cmd.Parameters.Add(new SqlParameter("@RETURN_VALUE", SqlDbType.NVarChar));
_cmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
_conn.Open();
_cmd.ExecuteNonQuery();
Int64 result = Int64.Parse(_cmd.Parameters["@RETURN_VALUE"].Value.ToString());
lblSumTotalPayShow.Text = result.ToString();
_conn.Close();
}
}
my SP is like this :
create Procedure [dbo].[sp_Noskheh_SumOfTotalPay]
@Co_ID int
As
-----------------
Declare @Sum nvarchar(50)
-----------------
BEGIN
Select @Sum = convert(nvarchar(50), SUM(TotalPay))
From Noskheh
Where (Co_ID = @Co_ID)
Return @Sum
END
and the error is in line (_cmd.ExecuteNonQuery();):
Error:
Sys.WebForms.PageRequestManagerServerErrorException: The conversion of
the nvarchar value ‘3955811801’ overflowed an int column. The
‘sp_Noskheh_SumOfTotalPay’ procedure attempted to return a status of
NULL, which is not allowed. A status of 0 will be returned instead.
Would you please help me to figure out this problem?
You are trying to convert a nvarchar value to a
intThe
Returnstatement must be an integer.Try changing your approach and in your Stored Proc do
Select @Suminstead ofreturn @sumThen instead of using
ExecuteNonQueryuseExecuteScalar