I have a form that contains buttons that refer to tables and the buttons represent tables. The default button image is free and I want the button image to change according to value in database table "free" or "busy" and I know there's a mistake in my code.
How to get this to work?
EDIT :
I have replaced the custom buttons with default stock buttons now it gives nothing and I checked the result of the query and it's correct but nothing changes and no errors.
My table is as follows:
| tablenum | tabestatusint |
|----------|---------------|
| 1 | 0 |
| 2 | 1 |
| 3 | 1 |
So if tabestatusint
is 0
it should change the image
Here's what I have tried :
public void checkSuites()
{
Dictionary<int, Control> btnList = new Dictionary<int, Control>();
btnList.Add(1, Button1);
btnList.Add(2, Button2);
SqlCommand checkSuite = new SqlCommand(
"SELECT tablestatusint FROM tablesstatustbl", cn);
SqlDataReader readSuite = checkSuite.ExecuteReader();
while (readSuite.Read())
{
int suiteIndex = Convert.ToInt32(readSuite["tblstatusint"]);
string suitePath = "tblstatusint" + suiteIndex;
foreach (Button key in btnList.Values)
{
if (key.Name == suitePath)
{
key.Image = My_Café_Manger.Properties.Resources.tablesbusy;
}
}
}
}