Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从数据库C获取checkedboxlist时如何检查该列表项#_C#_Asp.net_Checkboxlist - Fatal编程技术网

C# 从数据库C获取checkedboxlist时如何检查该列表项#

C# 从数据库C获取checkedboxlist时如何检查该列表项#,c#,asp.net,checkboxlist,C#,Asp.net,Checkboxlist,从数据库中提取时,如何自动检查CheckedBoxListItem 我已尝试此操作,但出现以下错误: 输入字符串的格式不正确 永远不要使用字符串连接来进行sql查询!请改用参数。切勿使用字符串连接进行sql查询!改用参数。 private void MyTodo_Project_Load(object sender, EventArgs e) { SqlConnection con3 = new SqlConnection(ConfigurationManager.ConnectionS

从数据库中提取时,如何自动检查
CheckedBoxListItem

我已尝试此操作,但出现以下错误:

输入字符串的格式不正确


永远不要使用字符串连接来进行sql查询!请改用参数。切勿使用字符串连接进行sql查询!改用参数。
private void MyTodo_Project_Load(object sender, EventArgs e)
{
    SqlConnection con3 = new SqlConnection(ConfigurationManager.ConnectionStrings["Conec"].ConnectionString);
    SqlCommand cmd3;
    string sql3 = " SELECT Task From Todaywork where Username='" + Login.recuser + "' and Active='1'";
    try
    {
        con3.Open();
        cmd3 = new SqlCommand(sql3, con3);
        string index = cmd3.ExecuteScalar().ToString();
        cmd3.Dispose();
        con3.Close();

        checkedListBoxongoing.SelectedItem = index;
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}