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.

3
  • Checkbox in a winform ? WPF ? MVC view ? Webform ? Commented Jan 30, 2016 at 21:59
  • Assuming that the id column is unique, then you need to use ExecuteScalar Commented Jan 30, 2016 at 22:00
  • Please find your solution in the revision history and post it as an answer of its own, thank you. Commented Jul 18, 2018 at 13:56

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.