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