2 回答
TA贡献1829条经验 获得超4个赞
真正的解决方案
因为我对上一个“解决方案”不满意,所以我尝试了更多并最终使用了这个:
MySqlCommand führerscheinstring = conn.CreateCommand();
führerscheinstring.CommandText = "SELECT führerschein FROM bewerber WHERE id = '" + textBoxrecruitingid.Text + "'";
string stringführerschein = führerscheinstring.ExecuteScalar().ToString();
char[] charSeparators = new char[] { ',' };
string[] result;
result = stringführerschein.Split(charSeparators, StringSplitOptions.None);
foreach (string entry in result)
{
if (entry == "A")
{
checkedListBoxrecruitingführerschein.SetItemChecked(0,true);
}
else if (entry == "B")
{
checkedListBoxrecruitingführerschein.SetItemChecked(1, true);
}
else if (entry == "BE")
{
checkedListBoxrecruitingführerschein.SetItemChecked(2, true);
}
else if (entry == "C1")
{
checkedListBoxrecruitingführerschein.SetItemChecked(3, true);
}
else if (entry == "C")
{
checkedListBoxrecruitingführerschein.SetItemChecked(4, true);
}
else if (entry == "C1E")
{
checkedListBoxrecruitingführerschein.SetItemChecked(5, true);
}
else if (entry == "CE")
{
checkedListBoxrecruitingführerschein.SetItemChecked(6, true);
}
else if (entry == "D1")
{
checkedListBoxrecruitingführerschein.SetItemChecked(7, true);
}
else if (entry == "D")
{
checkedListBoxrecruitingführerschein.SetItemChecked(8, true);
}
else if (entry == "D1E")
{
checkedListBoxrecruitingführerschein.SetItemChecked(9, true);
}
else if (entry == "DE")
{
checkedListBoxrecruitingführerschein.SetItemChecked(10, true);
}
else if (entry == "L")
{
checkedListBoxrecruitingführerschein.SetItemChecked(11, true);
}
else if (entry == "T")
{
checkedListBoxrecruitingführerschein.SetItemChecked(12, true);
}
else if (entry == "ADR")
{
checkedListBoxrecruitingführerschein.SetItemChecked(14, true);
}
else if (entry == "ADR Tank")
{
checkedListBoxrecruitingführerschein.SetItemChecked(15, true);
}
else if (entry == "Module vorhanden")
{
checkedListBoxrecruitingführerschein.SetItemChecked(16, true);
}
else if (entry == "Fahrerkarte vorhanden")
{
checkedListBoxrecruitingführerschein.SetItemChecked(17, true);
}
else
{
}
}
分配分隔符
char[] charSeparators = new char[] { ',' };
选择要检查的内容(17 是项目 ID(从 0 开始)true 表示将检查项目)
checkedListBoxrecruitingführerschein.SetItemChecked(17, true);
TA贡献1799条经验 获得超9个赞
“解决方案”
这并不是我的问题的真正解决方案,但我想分享我的解决方法。
我将可检查项的所有可能组合添加到数据库请求中,询问数据库条目是否是这些组合之一(代码中的示例)
MySqlCommand führerscheinab = conn.CreateCommand();
führerscheinab.CommandText = "SELECT count(*) FROM bewerber WHERE id = '" + textBoxrecruitingid.Text + "' and führerschein = 'A,B,'";
string countab = führerscheinab.ExecuteScalar().ToString();
MySqlCommand führerscheinabe = conn.CreateCommand();
führerscheinabe.CommandText = "SELECT count(*) FROM bewerber WHERE id = '" + textBoxrecruitingid.Text + "' and führerschein = 'A,BE,'";
string countabe = führerscheinabe.ExecuteScalar().ToString();
MySqlCommand führerscheinac1 = conn.CreateCommand();
führerscheinac1.CommandText = "SELECT count(*) FROM bewerber WHERE id = '" + textBoxrecruitingid.Text + "' and führerschein = 'A,C1,'";
string countac1 = führerscheinac1.ExecuteScalar().ToString();
MySqlCommand führerscheinac = conn.CreateCommand();
führerscheinac.CommandText = "SELECT count(*) FROM bewerber WHERE id = '" + textBoxrecruitingid.Text + "' and führerschein = 'A,C,'";
string countac = führerscheinac.ExecuteScalar().ToString();
MySqlCommand führerscheinac1e = conn.CreateCommand();
führerscheinac1e.CommandText = "SELECT count(*) FROM bewerber WHERE id = '" + textBoxrecruitingid.Text + "' and führerschein = 'A,C1E,'";
string countac1e = führerscheinac1e.ExecuteScalar().ToString();
剩下要做的就是为每个结果创建一个 if 语句,例如:
if (countab == 1)
{
check a and b
}
else if (countabe == 1)
{
check a and be
}
else if ( ... and so on
不是我想要的解决方案,而且肯定不是考虑到资源的最佳解决方案,但是是的..它有效^^
- 2 回答
- 0 关注
- 130 浏览
添加回答
举报