Solved

Simple search function in ASP.NET and C#

Posted on 2004-10-13
1
354 Views
Last Modified: 2008-02-01
Hi,

I want a simple search function:

-Preferably I want the search function to be available in all my pages, but it's no worries if I have a dedicated page where the search function fires from
Other:
-Search the field "Navn" in my "Pasientbok" table
-Search from a textbox
-Display it on a searchresultspage

I have tried this on my search page:
public string Sok
            {
                  get
                  {
                        return txtSok.Text;
                  }
            }


            

            private void Submit1_Click(object sender, System.EventArgs e)
            {
                  Server.Transfer("sokres.aspx");
            }

This on my search results page:
public Default fp;
private void Page_Load(object sender, System.EventArgs e)
            {
                  if (!IsPostBack)
                  {
                        
                        fp = (Default) Context.Handler;
                        BindData();
                  
                  }
            }

string strCommand = ("Select * From Pasientbok WHERE Navn LIKE '%fp.Sok%' ORDER BY Navn");

What's missing or wrong??
0
Comment
Question by:ginola14
1 Comment
 
LVL 8

Accepted Solution

by:
Razzie_ earned 125 total points
ID: 12303549
In your example, fp.Sok is codes as a string in the sql command. Use something like this:

string strCommand = ("Select * From Pasientbok WHERE Navn LIKE '%" + fp.Sok + "%' ORDER BY Navn");

If you are unsure about your SQL, you can always at the next line output the strCommand, like: Console.WriteLine(strCommand); to see the actual SQL query that will be send to the database.

HTH,

Razzie
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now