jeudi 19 novembre 2015

Assigning each column to corresponding checkbox

I have 33 checkboxes which is a bus seats with their own seat number, also i have 33 columns in my bus_seats table. In my form and database everything is set up. But I am stuck at assigning values from sql to checkboxes. I can do it manually setting

string sql = "SELECT * FROM bus_seats WHERE sefer_id = 1";
using (SQLiteCommand command = new SQLiteCommand(sql, connect))
{
    SQLiteDataReader reader = command.ExecuteReader();
    while (reader.Read())
    {
        if (Convert.ToInt32(reader["5"]) == 1)
        {
            checkBox5.BackColor = Color.CornflowerBlue;
        }
    }
}

As you can see in the code, reader["5"] is my 5th seat in sql table, and checkBox5 is my 5th seat in my form. I don't want to assign them manually and create huge "if" statements. Is there any easy way to compare column values and checkbox values? In my code reader["5"] == 1 means 5th Seat taken by a women(pink), 2 means its taken by a man(blue), 0 means empty(gray). I am trying to colorize checkbox background color by their sql values




Aucun commentaire:

Enregistrer un commentaire