Click here to Skip to main content
15,908,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to search Record using Multiple Textboxes in Multiple Columns On single Button click like this-

http://s9.postimg.org/mm65gbxxr/Design_Search_Application_like_this_and_clear_co.png[^]

Would it be Good To check for Null Values to search result like

C#
 if (TextBox2.Text == "")
       {

Then Search Via Column "Name"
}
else if(TextBox3.Text == "")
{

Search Via RollNumber

}


Just Want to know a Better idea to perform search can anybody suggest me thanks in advance :)
Posted

I'd normally have an SP doing the search.
The parameters for the SP would be null for the search criteria not specified.

The WHERE of the SQL woulld read something like

SQL
WHERE

table.Name = (IsNull(@Name, table.Name))
AND
table.RollNumber = (IsNull(@RollNumber, table.RollNumber))
 
Share this answer
 
You can build the query dynamic instead ,

before executing it.

C#
string qry="select details from table where";

if(txtbox1.text=="")
qry+="rollno ="+txtbox2.text;
if(textbox2.text=="")
qry+="name="+txtbox1.text;
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900