Solved

Simple search function in ASP.NET and C#

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
itextsharp with c# 3 35
ComboBox to String Not Working 5 43
c# deserialize JSON from web service using JsonConvert 9 61
WPF and Powershell button hover change text 5 63
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

738 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