3
Answers

Change label's button color when click with condition

Israel

Israel

8y
255
1
Hi,
I have one label(lbl_signal):
Then when I run my program my label will receive data from a specific column's database like this:
 
string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Foods\App_Data\office.mdb;Persist Security Info=False";
OleDbConnection sqlCon = new OleDbConnection(connectionString);
sqlCon.Open();
 
string commandString = "select * from myTable where S ='" + "*" + "'";
OleDbCommand sqlCmd = new OleDbCommand(commandString, sqlCon);
OleDbDataReader read = sqlCmd.ExecuteReader();
if (read.HasRows)
{
while (read.Read())
{
lbl_signal.Text = read["signal"].ToString();
}
}
else
{
//line of code
}
read.Close();
sqlCon.Close();
 
Then if there is a word connected it's should be automatically in green's color. If its disconnected it's should be automatically in red's color.
How can I do it with a condition please?
 
Thanx,
Israel. 
Answers (3)