SQL 到复选框 ||按钮 if/else 上的复选框情况 (C#)

本文关键字:复选框 情况 按钮 if SQL else | 更新日期: 2023-09-27 18:32:31

谢谢你们!!真的!!按钮上的复选框情况 如果/否则(已解决)

但是我如何将 sql 情况 e.x 真/假转移到复选框。或者,如果有另一种方法可以做到这一点:当我打开一个w通知时,我想记住我的复选框条件是什么。

SQL 到复选框 ||按钮 if/else 上的复选框情况 (C#)

您需要

像这样使用 ExecuteScalar 方法:

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
{
    //..
}

请注意,根据您的问题,我假设rent_panel列的类型为 bit(可以是真或假)。

我还假设 id 列具有唯一值(它是主键,对吧?

旁注:应始终使用 using 关键字释放连接和命令对象。看看这个答案。

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