如何阻止数据在标签中重复?
此时我的余额会在其旁边添加一个值,例如余额: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();
答案 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属性。