I am working on an application with about 20 text boxes and 26 checkboxes which is quite a load I know , but is necessary for the task.Currently I am struggling to be able to search by multiple checkboxes at the same time. I was wondering if there would be any easier way to go about this logically without a ton of if statements.
Here is my current SQL select statement:
`string str = "select * from engineering where JobNumber like '%' + @search + '%' AND DateOrdered like '%' + @search1 + '%' AND Title like '%' + @search2 + '%' AND PhysicalAddressComplete like '%' + @search3 + '%' AND County like '%' + @search4 + '%' AND Client like '%' + @search5 + '%' AND Contact like '%' + @search6 + '%' AND ContactTitle like '%' + @search7 + '%' AND MailingAddressComplete like '%' + @search8 + '%' AND BusinessPhone like '%' + @search9 + '%' AND CellPhone like '%' + @search10 + '%' AND Email like '%' + @search11 + '%' AND OpenStatus like '%' + @search12 + '%' AND CloseStatus like '%' + @search13 + '%' AND Cabinet like '%' + @search14 + '%' AND Roll like '%' + @search15 + '%' AND Drawer like '%' + @search16 + '%' AND ConstructionDrawings like '%' + @search17 + '%' AND Fee like '%' + @search18 + '%' AND ConstructionCost like '%' + @search19 + '%' AND ProjectDescription like '%' + @search20 + '%' ";
if (chkEducational.Checked)
str += "AND Education = @Education";
else if (chkMedical.Checked)
str += "AND Medical = @Medical";
else if (chkReligious.Checked)
str += "AND Religious = @Religious";
else if (chkMulti.Checked)
str += "AND MultiFamily = @MultiFamily";
else if (chkStudent.Checked)
str += "AND Student = @Student";
else if (chkAssisted.Checked)
str += "AND Assisted = @Assisted";
else if (chkSingleFamily.Checked)
str += "AND Single = @Single";
else if (chkBridge.Checked)
str += "AND Bridge = @Bridge";
else if (chkIntersection.Checked)
str += "AND Intersection = @Intersection";
else if (chkRoadway.Checked)
str += "AND Roadway = @Roadway";
else if (chkDesign.Checked)
str += "AND DesignBuild = @DesignBuild";
else if (chkTransOther.Checked)
str += "AND TransportationOther = @TransportationOther";
else if (chkRetailSmall.Checked)
str += "AND SmallRetail = @SmallRetail";
else if (chkRetailLarge.Checked)
str += "AND LargeRetail = @LargeRetail";
else if (chkParks.Checked)
str += "AND Parks = @Parks";
else if (chkIndustrial.Checked)
str += "AND Industrial = @Industrial";
else if (chkUtility.Checked)
str += "AND Utility = @Utility";
else if (chkGCSmall.Checked)
str += "AND GCSmall = @GCSmall";
else if (chkGCLarge.Checked)
str += "AND GCLarge = @GCLarge";
else if (chkOffice.Checked)
str += "AND Office = @Office";
else if (chkOther.Checked)
str += "AND Other = @Other";
else if (chkMunicipal.Checked)
str += "AND Municipal = @Municipal";
else if (chkPrivate.Checked)
str += "AND Privates = @Privates";
else if (chkInstitutional.Checked)
str += "AND Institutional = @Institutional";
else if (chkMilitary.Checked)
str += "AND Military = @Military";
else if (chkArchive.Checked)
str += "AND Archived = @Archived";`
This statement works as I am able to search by any amount of text as well as checkboxes however when it comes to checkboxes some records do not correlate to the searches. For example if I was to check the Archive checkbox along with the Military Checkbox , I would want the results to be only those with BOTH of those boxes checked, however when I do this with my code I also get the records with only the military box checked as well. It seems as if the Else If statement acts as a pecking order. Any help would be appreciated.
Aucun commentaire:
Enregistrer un commentaire