c#停止在标签中重复数据

时间:2012-03-08 10:46:09

标签: c#

如何阻止数据在标签中重复?

此时我的余额会在其旁边添加一个值,例如余额:500.000,500.000

我只希望它打开一次。这里是我正在使用的代码

SqlDataReader readdata;

try
{

    sqlCommandbalance.Connection.Open();
    sqlCommandbalance.Parameters["@accountID"].Value = show.accountID;
    readdata = sqlCommandbalance.ExecuteReader();
    string balanceDB = null;
    string availableBalance = null;
    while (readdata.Read())
    {
        balanceDB = readdata["balance"].ToString();
        availableBalance = (Convert.ToDecimal(readdata["balance"].ToString()) + Convert.ToDecimal(readdata["overdraftlimit"])).ToString();
    }
    sqlCommandbalance.Connection.Close();
    balanceShow.Text += " " + balanceDB.ToString();
    availablebalanceShow.Text += " " + availableBalance.ToString();

1 个答案:

答案 0 :(得分:2)

你需要改变这个:

balanceShow.Text += " " + balanceDB.ToString();
availablebalanceShow.Text += " " + availableBalance.ToString();

balanceShow.Text = " " + balanceDB.ToString();
availablebalanceShow.Text = " " + availableBalance.ToString();
<=> + =相当于这样说:

balanceShow.Text = balanceShow.Text + " " + balanceDB.ToString();

这就是为什么它总是将文本附加到现有文本。您只想将余额值分配给Text属性。