Here is the implementation of multi-condition query through the statement stitching.
Main code:
<%@ page language= "C #" autoeventwireup= "true" codefile= "Default19.aspx.cs" inherits= "Default19"%><! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
protected void Btn_search_click (object sender, EventArgs e) { String strfacy = "SELECT * from Torderreview where 1 =1 "; if (!string. IsNullOrEmpty (tb_x1. Text.tostring ())) { strfacy + = "and" + DropDownList1.SelectedValue.ToString () + "like '%" + tb_x1. Text.tostring () + "% '"; } if (!string. IsNullOrEmpty (tb_x2. Text.tostring ())) { strfacy + = "and" + DropDownList2.SelectedValue.ToString () + "like '%" + tb_x2. Text.tostring () + "% '"; } if (!string. IsNullOrEmpty (tb_x3. Text.tostring ())) { strfacy + = "and" + DropDownList3.SelectedValue.ToString () + "like '%" + tb_x3. Text.tostring () + "% '"; } Strfacy + = "ORDER by OrderID Desc"; Gridbind (strfacy); }
The general situation is this way, good use, than I used the method is much simpler Multi-criteria queries that implement multiple DropDownList and multiple textbox in ASP. NET (C #)