這是我的問題。我有一個可以用關鍵字實現研究的文本框。我有一個有不同主題(ADV,Logistic,Finance,Administration)的清單框來過濾sql查詢。如果我搜索關鍵詞並檢查了「邏輯」,則返回結果將僅與「物流」相關。這很好,問題是,如果我檢查2複選框,例如「邏輯」和「財務」,我只會得到與「邏輯」相關的結果,但我想要得到2個結果。 20分鐘前,突然不再工作了,我不記得原因。誰能告訴我我錯過了什麼?從複選框過濾sql查詢的c#問題
這裏是我的代碼:
string word = tbSearch.Text;
string strSql = @"SELECT CAST(ID as VarChar(50)) ID, Aggregation, DateDerniereSolution, DateDescription, DerniereSolution, DescriptionDemande, FileDeTraitement, NomContact, Numero, SousRubrique, TitreDemande
FROM cfao_DigiHelp_index.DigiHelpData WHERE (1 = 1)";
string selectedValue = "";
bool IsFirst = false;
strSql += @" AND (";
foreach (ListItem item in CheckboxID.Items)
{
if (item.Selected)
{
selectedValue += item.Value ;
if (IsFirst)
{
strSql += " OR ";
}
strSql += " SousRubrique Like '%" + selectedValue + "%' ";
IsFirst = true;
}
if (CheckboxID.SelectedIndex == -1)
{
Label2.Visible = true;
Label2.Text = "Veuillez cocher au moins une rubrique";
}
}
strSql += @" )";
你能發表查詢嗎? – Berkay
你的意思是'不再工作',你是否得到任何錯誤或沒有得到預期的輸出? –