Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 1st, 2008, 12:47 PM
Authorized User
 
Join Date: Jul 2004
Location: Burlington, NJ, USA.
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

Reply With Quote
  #2 (permalink)  
Old April 1st, 2008, 03:35 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
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
Reply With Quote
  #3 (permalink)  
Old April 2nd, 2008, 09:40 AM
Authorized User
 
Join Date: Jul 2004
Location: Burlington, NJ, USA.
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
Reply With Quote
  #4 (permalink)  
Old April 2nd, 2008, 10:25 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 05:46 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.