2 回答

TA貢獻(xiàn)1829條經(jīng)驗 獲得超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[] { ',' };
選擇要檢查的內(nèi)容(17 是項目 ID(從 0 開始)true 表示將檢查項目)
checkedListBoxrecruitingführerschein.SetItemChecked(17, true);

TA貢獻(xiàn)1799條經(jīng)驗 獲得超9個贊
“解決方案”
這并不是我的問題的真正解決方案,但我想分享我的解決方法。
我將可檢查項的所有可能組合添加到數(shù)據(jù)庫請求中,詢問數(shù)據(jù)庫條目是否是這些組合之一(代碼中的示例)
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();
剩下要做的就是為每個結(jié)果創(chuàng)建一個 if 語句,例如:
if (countab == 1)
{
check a and b
}
else if (countabe == 1)
{
check a and be
}
else if ( ... and so on
不是我想要的解決方案,而且肯定不是考慮到資源的最佳解決方案,但是是的..它有效^^
- 2 回答
- 0 關(guān)注
- 164 瀏覽
添加回答
舉報