Solved

Simple search function in ASP.NET and C#

Posted on 2004-10-13
1
351 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

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 article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

760 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

18 Experts available now in Live!

Get 1:1 Help Now