0

残りの与信限度額を計算するクラスがあります。そして、DataTable を介して値を返します。しかし、IF条件では、「入力文字列が正しい形式ではありませんでした。」というエラーがスローされます。コードに問題があります。

助けてください、事前に感謝します

        string cmd2 = "select sum(FacilityAmountINR),sum(LCAmountPaid) from FacilityIssueDetails where Status='open' AND LCType = 'Inland LC'";
        DataTable a = DbRdRw.SqlDbRead(cmd2, "FacilityIssueDetails");
        decimal AvailInlandLC = 0;
        string totcred = Convert.ToString(a.Rows[0]["Column1"]);
        string totpaid = Convert.ToString(a.Rows[0]["Column2"]);
        if (totcred != null && totpaid != null)
        {
            decimal TotalAmountCredit = Convert.ToDecimal(totcred);// error here
            decimal TotalAmountpaid = Convert.ToDecimal(totpaid); // error here
            AvailInlandLC = InlandLC - TotalAmountCredit + TotalAmountpaid;
        }
        //*************************************************************************
        DataTable AvailableLimitTable = new DataTable();
        AvailableLimitTable.Columns.Add("LCType",typeof (string));
        AvailableLimitTable.Columns.Add("TotalLimit",typeof (decimal));
        AvailableLimitTable.Columns.Add("AvailableLimit",typeof (decimal));

        DataRow dr = AvailableLimitTable.NewRow();
        dr["LCType"] = "Inland LC";
        dr["TotalLimit"] = InlandLC;
        dr["AvailableLimit"] = AvailInlandLC;
        AvailableLimitTable.Rows.InsertAt(dr, 0);
4

1 に答える 1

0

データベースから NULL 値を取得している場合は、if ループ条件を変更してみてください...

if (totcred != null && totpaid != null && totcred != "Null" && totpaid != "Null" )
        {
            decimal TotalAmountCredit = Convert.ToDecimal(totcred);// error here
            decimal TotalAmountpaid = Convert.ToDecimal(totpaid); // error here
            AvailInlandLC = InlandLC - TotalAmountCredit + TotalAmountpaid;
        }
于 2013-04-19T05:59:05.297 に答える