How would i stop data repeating itself in a label?
at the moment my balance keep adding a value next to it for e.g balance: 500.000, 500.000
where i only want it to open once. here the code i am using
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();
you need to change this:
to
the += is equivalent to saying this:
which is why it is always appending the text to the existing text. You want to just assign the value of balance to the Text property.