Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Simple search function in ASP.NET and C#

Posted on 2004-10-13
1
Medium Priority
?
375 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 500 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

971 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