我的代码如下所示:
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();
}
}
我的SP是这样的:
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
并且错误在行中(_cmd.ExecuteNonQuery();):
错误:
Sys.WebForms.PageRequestManagerServerErrorException:nvarchar 值“3955811801”的转换溢出了一个 int 列。“sp_Noskheh_SumOfTotalPay”过程试图返回 NULL 状态,这是不允许的。将改为返回状态 0。
你能帮我解决这个问题吗?