显示不正确的成本

时间:2015-06-01 19:48:40

标签: c# asp.net if-statement

我的目标是在网页上显示为期一天的会议的费用,即50.00美元。但是,我一直得到0.00美元作为回报。我在SQL中测试了我的SELECT语句,它正在检索正确的数据。现在我已将问题缩小到 PayBackCC 方法中的if...else if语句中,但我不确定。它应该从变量cOneDCost获得成本。任何帮助表示赞赏。

背后的代码

protected void PayBackInfo()
{
    try
    {
        con.Open();
        SqlCommand PBCredit = new SqlCommand("SELECT * FROM PaymentInfo, ConferenceReg WHERE PaymentInfoID=PaymentInfoIDNum AND PaymentInfoID=@payID AND ConferenceReg.Deleted='N' AND ConferenceIDNum=@confID", con);
        PBCredit.Parameters.AddWithValue("@confID", confID);
        PBCredit.Parameters.AddWithValue("@payID", Request.QueryString["payID"]);

        SqlDataReader readerPB = PBCredit.ExecuteReader();
        while (readerPB.Read())
        {
            piID = readerPB["PaymentInfoID"].ToString();
            cID = readerPB["ConferenceIDNum"].ToString();
            poID = readerPB["PurchaseOrder"].ToString();
            partnersNum = readerPB["PartnersIDNum"].ToString();
            cFullCost = Convert.ToDecimal(readerPB["ConferenceFullFee"]).ToString("#,##0.00");
            cOneDCost = Convert.ToDecimal(readerPB["ConferenceOneDayFee"]).ToString("#,##0.00");
            partnersCost = Convert.ToDecimal(readerPB["PartnersFee"]).ToString("#,##0.00");

            PayBackCC();
        }
        readerPB.Close();
    }
    finally
    {
        con.Close();
    }
}


private void PayBackCC()
{
    if (!partnersNum.Equals("null") || !partnersNum.Equals("0"))
    {
        msgLbl.Text = "$" + partnersCost;
    }
    else if (!cFullCost.Equals("0"))
    {
        msgLbl.Text = "$" + cFullCost;
    }
    else if (!cOneDCost.Equals("0"))
    {
        msgLbl.Text = "$" + cOneDCost;
    }
}

1 个答案:

答案 0 :(得分:0)

请更改

 if (!partnersNum.Equals("null") || !partnersNum.Equals("0"))

 if (!String.IsNullOrEmpty(partnersNum) || !partnersNum.Equals("0"))

除非您期望查询中出现“null”字符串