Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 1st, 2008, 12:47 PM
Authorized User
 
Join Date: Jul 2004
Posts: 16
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via ICQ to meichmann Send a message via AIM to meichmann Send a message via Yahoo to meichmann
Default Search box on a Database results page

Hello Everyone,
     I have a small website with 4 buttons. Each button will take you to a page that retrieves database information and places the information in a table.

     What I would like to do is add a search feature on that page so people can drill further down to get a more refined result. Is it possible for me to place a search field on that page and have the page refresh with the more drilled down results?

Thank you for your time in Advance.

Matt

 
Old April 1st, 2008, 03:35 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

It certainly is. You'll need to determine how you want people to be able to search the data and provide the search logic for it. Then you just limit the database results by incorporating the user's search value into the query.

-Peter
peterlanoie.blog
 
Old April 2nd, 2008, 09:40 AM
Authorized User
 
Join Date: Jul 2004
Posts: 16
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via ICQ to meichmann Send a message via AIM to meichmann Send a message via Yahoo to meichmann
Default

Ok, but how do I go about doing this?

When the user first hits the page, the following SQL statement automatically runs:

"SELECT * FROM dbo.Bids WHERE Active='1' AND DATEDIFF(day,OpeningDate,GetDate()) < 1 ORDER BY BidCategory, BidName, ExpirationDate" and the results are shown.

Now, I have the search feature on the page which will allow them to search by Bid Name. When they type in a bid name, I'd like to refresh the page and append the SQL statement to say:

"SELECT * FROM dbo.Bids WHERE Active='1' AND DATEDIFF(day,OpeningDate,GetDate()) < 1 AND BidName LIKE 'Value' ORDER BY BidCategory, BidName, ExpirationDate"

That way the original statement stays intact and it appends the new search criteria.

Of course, if the user just hits the submit button without inputing any data, then it will refresh without the added criteria.

Is this done with a function and hidden form values or is it something else?

Thank you for your time.

Matt
 
Old April 2nd, 2008, 10:25 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

When the page posts back, the search value will be in the text box. Construct the new query as you describe and get the value from <textboxid>.Text. You'll probably want to wrap the search string in % so it will find the search string within the column value instead of expecting it to be exact.

You'll probably want to build this query using a SQL command object so you don't have to worry about the SQL injection risk. You can add a parameter into your query, then add the search value to the command's parameters collection. Something like this:

sqlCommand.CommandText = "SELECT * FROM dbo.Bids WHERE Active='1' AND DATEDIFF(day,OpeningDate,GetDate()) < 1 AND BidName LIKE @BidSearch ORDER BY BidCategory, BidName, ExpirationDate"
sqlCommand.Parameters.Add(New SqlParameter("@BidSearch", String.Format("%{0}%", <textboxid>.Text)))


-Peter
peterlanoie.blog





Similar Threads
Thread Thread Starter Forum Replies Last Post
Count in combo box(display results in text box) mboyisis Access 4 April 4th, 2008 07:08 AM
Easier page navigation of search results gs99 Forum and Wrox.com Feedback 0 February 2nd, 2007 09:38 PM
How do I display search results... aspiretech9 PHP How-To 1 April 26th, 2005 10:12 AM
How do I display search results... aspiretech9 PHP Databases 1 April 25th, 2005 12:11 PM
how to count the database search results of record gilgalbiblewheel Classic ASP Databases 2 July 31st, 2004 10:37 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.