Help for select statement
-
Hi ALL In my application i wrote a query like this "select * from Cand_Information where Category= '" & DpCat.SelectedItem.Text & "' or (First_Name= '" & TxtFname.Text & "' or Last_Name= '" & TxtLname.Text & "' or Sex= '" & DpdownSex.SelectedItem.Text & "' )" But i want the Category field to be mandatory so i kept it outside the bracket. so that it should only display data with that particular Category. so rest of the fields are optional. How to write the correct one pl help Regards
Prakash Mishra(Banglore,India)
-
Hi ALL In my application i wrote a query like this "select * from Cand_Information where Category= '" & DpCat.SelectedItem.Text & "' or (First_Name= '" & TxtFname.Text & "' or Last_Name= '" & TxtLname.Text & "' or Sex= '" & DpdownSex.SelectedItem.Text & "' )" But i want the Category field to be mandatory so i kept it outside the bracket. so that it should only display data with that particular Category. so rest of the fields are optional. How to write the correct one pl help Regards
Prakash Mishra(Banglore,India)
-
Change the or to an and "select * from Cand_Information where Category= '" & DpCat.SelectedItem.Text & "' and (First_Name= '" & TxtFname.Text & "' or Last_Name= '" & TxtLname.Text & "' or Sex= '" & DpdownSex.SelectedItem.Text & "' )" Ben
HI i tried it before also but according to specification if i select only Category then also records should be displayed. if i put and there then i need to select at least one field from the or options. else it not show any record. Regards
Prakash Mishra(Banglore,India)
-
Hi ALL In my application i wrote a query like this "select * from Cand_Information where Category= '" & DpCat.SelectedItem.Text & "' or (First_Name= '" & TxtFname.Text & "' or Last_Name= '" & TxtLname.Text & "' or Sex= '" & DpdownSex.SelectedItem.Text & "' )" But i want the Category field to be mandatory so i kept it outside the bracket. so that it should only display data with that particular Category. so rest of the fields are optional. How to write the correct one pl help Regards
Prakash Mishra(Banglore,India)
Try this:
string optionalFiters=""; if(TxtFname.Text!="") optionalFiters+=" and First_Name= '" & TxtFname.Text + "'"; if(TxtLname.Text!="") optionalFiters+=" and Last_Name= '" & TxtLname.Text + "'"; if(DpdownSex.SelectedItem.Text!="") optionalFiters+=" and Sex= '" & DpdownSex.SelectedItem.Text + "'";
Regards, Arun Kumar.A