i have five conditions that i have to check i.e does the user wants to search using this field or not. There are four combo boxes and one text field. user can search using any field or multiple fields as he/she pleases so to check which field did the user selected i have constructed several if and else if statements but doing so for only two conditions i realized how tedious task this will be for five conditions is there a better way to do this?
if (cmbAgent.Text=="")
{
if (cmbDegree.Text=="")
{
OleDbDataAdapter da = new OleDbDataAdapter("Select * from UniversityData", connection);
}
else
{
OleDbDataAdapter da = new OleDbDataAdapter("Select * from UniversityData where Expertise like '%" + cmbDegree.Text + "%' ", connection);
}
}
else if(cmbDegree.Text=="")
{
OleDbDataAdapter da = new OleDbDataAdapter("Select * from UniversityData where SourceOfContact like '%"+cmbAgent.Text+"%' ", connection);
}
else
{
OleDbDataAdapter da = new OleDbDataAdapter("Select * from UniversityData where SourceOfContact like '%" + cmbAgent.Text + "%' and Expertise like '%"+cmbDegree .Text +"%' ", connection);
}
Aucun commentaire:
Enregistrer un commentaire