0

我有一个存储程序。从此我想要输出值,但显示以下错误:

System.OverflowException:对于 Int32,值太大或太小。

我的店铺流程

ALTER proc dbo.[RECnoofDue]        
@acno varchar(100),
@NoofDue numeric(18,2) output        
as 
Begin
select @NoofDue=isnull(SUM(Avgr),0) from (
select NoOfDue, LHEMI, TotalEMIDue, sunday, Avgr from 
(SELECT     COUNT(LHID) AS NoOfDue, LHEMI, SUM(LHEMI) AS TotalEMIDue, 
SUM((Case when LHSundryBalance is null then 0 else LHSundryBalance end)) AS sunday,
((SUM(LHEMI)-SUM((Case when LHSundryBalance is null then 0 else LHSundryBalance end))) / LHEMI) AS Avgr
FROM dbo.TblLoanHistory WHERE (LHAcNo = @acno) AND 
(LHEMIPaid = 0 OR LHEMIPaid IS NULL)AND (LHFileStatus IS NULL) GROUP BY LHSundryBalance, LHEMI,LHFileStatus ) x
union
(SELECT     COUNT(LHID) AS NoOfDue, LHEMI, SUM(LHTotalOverDue) AS TotalEMIDue, 
SUM((Case when LHSundryBalance is null then 0 else LHSundryBalance end)) AS sunday,
((SUM(LHTotalOverDue)-SUM((Case when LHSundryBalance is null then 0 else LHSundryBalance end))) / LHEMI) AS Avgr
FROM dbo.TblLoanHistory WHERE (LHAcNo = @acno) AND (LHEMIPaid = 0 OR LHEMIPaid IS NULL) AND 
(LHFileStatus = 'BK')GROUP BY LHSundryBalance, LHEMI)) bb

end

我的 ASP.NET C# 代码

private double NOofDueCount()
    {
        using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["OptimaWebCustomerQueryCon"].ConnectionString))
        using (SqlCommand cmd = new SqlCommand("dbo.RECnoofDue", conn))
        {
            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.Add("@acno", SqlDbType.Int);
            cmd.Parameters.Add("@NoofDue", SqlDbType.Int).Direction = ParameterDirection.Output;
            cmd.Parameters["@acno"].Value = hfLoanAcNo.Value;
            conn.Open();
            cmd.ExecuteNonQuery();
            using (SqlDataReader dr = cmd.ExecuteReader())
            {
                if (dr.Read())
                {
                    return Convert.ToDouble(cmd.Parameters["@NoofDue"].Value);
                    //int contractID = Convert.ToInt32(cmd.Parameters["@NoofDue"].Value);
                }
            }
            conn.Close();
            return 0;
        }
    }
4

1 回答 1

2

尝试使用decimal( SqlDbType.Decimal) 代替int,并确保您@acno的是string, ( SqlDbType.NVarChar)

cmd.Parameters.Add("@acno", SqlDbType.NVarChar);
cmd.Parameters.Add("@NoofDue", SqlDbType.Decimal).Direction = ParameterDirection.Output;

...

return Convert.ToDecimal(cmd.Parameters["@NoofDue"].Value);

或者可能是double( SqlDbType.Float),这可能是最初的意图,因为您的方法返回 a double

cmd.Parameters.Add("@acno", SqlDbType.NVarChar);
cmd.Parameters.Add("@NoofDue", SqlDbType.Float).Direction = ParameterDirection.Output;

...

double NoofDue = Convert.ToDouble(cmd.Parameters["@NoofDue"].Value);
于 2013-10-26T14:13:48.057 回答