Click here to Skip to main content
12,954,672 members (56,310 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hi to all..
i am using with sql database and my question is that

i have 5 text boxes...

Enter UId ...... textBox1
Enter Name.....textBox2
Enter City/Village .....textBox3
Enter State ....TextBox4
Enter Country ....TextBox5
button for search
(it depends on user how many entries he fills out of five textboxes)
i want to implement search in my page in a manner that search result come on behalf of data entered in textboxes by User..(he select all information of user from table where search matches)

for eg:-
if he enter Name='raju' and State='hariyana' then result would be all Raju in state hariyana
and if he only enters State='hariyana' then results come is all user of hariyana
this types of result i want

i hope u can understand what i want to do

actually problem i am facing is that if i use permutation and combination for this then it becomes more complex and more chances of mistakes...
i think there will be a simple method for doing this.
Pls suggest frnds and thanx in advance....
Posted 12-Feb-13 22:20pm
Updated 13-Feb-13 1:34am
Sergey Alexandrovich Kryukov 13-Mar-13 15:40pm
Please stop posting non-answers as "solution". It can give you abuse reports which eventually may lead to cancellation of your CodeProject membership. And the fact you even self-accepted on formally is just outrageous, a sure way for a ban. I hope you won't do it after this warning.

Comment on any posts, reply to available comments, or use "Improve question" (above).
Also, keep in mind that members only get notifications on the post sent in reply to there posts.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1


Add few lines of code to first check whether the textboxes are not null or empty.If no then append all the entered values of the text boxes with few strings and display them in a result label.

You might try the below:

protected void Button1_Click(object sender, EventArgs e)
      if(!string.IsNullOrEmpty(textbox1.Text)&&(!string.IsNullOrEmpty(textbox2.Text))&&so on..check for all the text boxes)
           LabelResult.Text="All"+textbox1.Text+"in City/Village"+textbox2.Text+"of state"+textbox3.Text;
            write some code on the else part depending upon your logic

Hope it helps..

Rate this: bad
Please Sign up or sign in to vote.

Solution 3

This kind of functionality should be handled at database level. What you can do is:

1) Pass all these fields as parameters to your stored procedure.
2) Create two temporary tables(PrimaryTable and SecondaryTable) with the columns you want to return.
3) Select all the records from your original table and fill the PrimaryTable with them.

Now comes the good part

if @userid <> ''
truncate table SecondaryTable
insert into SecondaryTable
select * from PrimaryTable where userId = @userid
truncate table PrimaryTable
insert into PrimaryTable
select * from SecondaryTable
truncate table SecondaryTable

--Repeat till you have non-blank parameters.

This is just a sample. The idea is to return all the rows without any condition then based on each non-blank parameter, The records are selected from PrimaryTable to SecondaryTable, Empty PrimaryTable and Replace the records with filtered records, Empty the SecondaryTable. This whole process goes on for all the parameters. In the end return PrimaryTable.

Give it a try and tell if it is of any use for you?

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

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,539
CHill60 3,490
Maciej Los 3,153
ppolymorphe 2,030
Jochen Arndt 1,975

Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 16 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100