Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi to all..
i am using asp.net 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
Updated 13-Feb-13 1:34am
v2
Comments
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.
—SA

Hi,

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:

C#
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;

        }
      else
          {
            write some code on the else part depending upon your logic
           }

   }

Hope it helps..

regrds
Anurag
 
Share this answer
 
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

4)
SQL
if @userid <> ''
BEGIN
truncate table SecondaryTable
insert into SecondaryTable
select * from PrimaryTable where userId = @userid
truncate table PrimaryTable
insert into PrimaryTable
select * from SecondaryTable
truncate table SecondaryTable
END



--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?
 
Share this answer
 

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