1

Thank You guys!!! really!! checkbox situation on button if/else (solved)

but how can i transfer a sql situation e.x True/false to checkbox. Or if there is another way to do this: When i open a winform i want to keep in memory what was my checkbox condition.

Cœur
  • 37,241
  • 25
  • 195
  • 267
DIMITRIS
  • 33
  • 8

2 Answers2

2

You need to use the ExecuteScalar method like this:

SqlCommand cmd = new SqlCommand("select rent_panel from parameters where id= '1'", con);

con.Open();

bool rent_panel = (bool)cmd.ExecuteScalar();

if (rent_panel == true) 
{
    //..
}
else
{
    //..
}

Please note that based on your question, I am assuming that the rent_panel column is of type bit (it can be either true or false).

I am assuming also that the id column has unique values (it is the primary key, right?)

Side note: you should always dispose your connection and command objects using the using keyword. Take a look at this answer.

Community
  • 1
  • 1
Yacoub Massad
  • 27,509
  • 2
  • 36
  • 62
0
SqlConnection con = new SqlConnection("Your Data Source");
SqlCommand cmd = new SqlCommand("select rent_panel from parameters where id= '1'", con);
con.Open();
bool rent_panel = (bool)cmd.ExecuteScalar();
if (rent_panel)  //(rent_panel == true) 
{
//..
}
else
{
    //..
}
con.close();