Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Simple search function in ASP.NET and C#

Posted on 2004-10-13
1
Medium Priority
?
371 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
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…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

715 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