我的代碼,如下所示:ExecuteNonQuery()錯誤 - > nvarchar值'3955811801'的轉換溢出了一個int列。
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: 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.
請你幫我弄清楚這個問題嗎?
Noskheh.Co_ID的數據類型是什麼? @Co_ID = 3955811801? – 2010-12-20 20:15:45