Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases 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 March 10th, 2004, 01:39 PM
Registered User
 
Join Date: Feb 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default searching a database

I am writing some ASP, but I want to code in a search box that will accept a string from the user and retrieve the info from a SQL Server 2000 database with about 8 tables. Do I have to code it on the Sql side, ASP side or both? Wha would the code be?

 
Old March 10th, 2004, 03:07 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

This is a pretty broad question.

You'll have to code it in both ASP and SQL. You need a form for the user to enter their search criteria, you'll need ASP to process that form and you'll have to write some SQL to look up the results from all tables you wish to search from.

Peter
------------------------------------------------------
Work smarter, not harder.
 
Old March 10th, 2004, 06:56 PM
Authorized User
 
Join Date: Jun 2003
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Default

you can create the form pretty fast in HTML you submit the form as POST or GET (your choice) In the page you submit to use Request.QueryString("fieldName") and sned the value to the database.

sample for Form:

<html>
<FORM NAME="tempQuery" ACTION="destinationPage.ASP" METHOD="Get">
    <h1>Your Headline</h1>

        I want to search for:<input type="text" NAME="searchString" VALUE="">
        <INPUT type="submit" value="Continue Next">
        </table>
</form>
</html>

sample for the destination:
<%option explicit%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">


<html>
<head>
<%
DIM searchString, objCommand, objRS, sqlStrDef
searchString = Request.QueryString("searchString")
%>
    <title> SearchReturn</title>

<%



%>
</head>

<body>
<%
sqlStrDef= "SELECT field1, field2, field3 FROM tableName WHERE field1 = '" & searchString & "'"
Set objCommand = Server.CreateObject("ADODB.Command")
objCommand.ActiveConnection = strConn
objCommand.CommandText = sqlStrDef
'executing and resetting to Nothing
objCommand.CommandType = adCmdText
Set objRS = objCommand.Execute
Set objCommand = Nothing

objRS.movefirst
WHILE NOT objRS.eof

RESPONSE.WRITE "<h1>this is your return</h1>
RESPONSE.WRITE field1 & field2 & field3
%>
</body>
</html>

something like that shoudl work.

WATCHOUT for special characters especially the mean single quote!!!!

... there is always more to learn...





Similar Threads
Thread Thread Starter Forum Replies Last Post
searching a database mark jonas MySQL 13 January 19th, 2007 10:01 AM
Searching through a database d5t ASP.NET 1.0 and 1.1 Basics 6 October 27th, 2006 07:10 AM
help with Database searching europhreak Classic ASP Basics 1 February 8th, 2006 07:30 AM
Searching the database...HELP! Zedman BOOK: Beginning ASP 3.0 6 September 30th, 2004 09:52 AM
Searching trough a database toni_montana PHP How-To 2 September 25th, 2004 09:17 AM





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