PDA

View Full Version : can anyone help me with a basic ASP search script for a Access database


r5gttraider
06-08-2005, 12:47 AM
:D I am currently building my 1st website. I would like to have a search feature which allows me to search a basic MS access database with fields such as Year,Colour and model using a HTML form.

:( my problem is with the ASP code i am a complete novice and dont have a clue.

:( Can anyone point me in the right direction of some basic ASP scripts that allow me to search a MS access database.

Before you say use google i have tried and the only ones i can find are far to complex for or you have to pay for and after hours of searching i am none the wiser and have found nothing to help me. :mad:

:confused: so can anyone point me in the right direction of some basic examples i can use to get my head around or do you have some examples you can show me ?.

:o Any help or advice would be much aprechiated
Regards R5



:D PS hello to the forum, go easy on me im a newbie

Basscyst
06-08-2005, 12:59 AM
This is the best IMO.

http://www.w3schools.com

ASP and ADO are what you want to look into.

Have fun,

Basscyst

miranda
06-08-2005, 02:18 AM
what you want is a SQL select statement.
lets say your input field is named search, and you want to see if the search word or string is in the table.

Dim search : search = "%" & Request.Form("search") & "%"
This will give you string with the wildcards around it so you can now define your select statement.
SELECT * FROM yourTable WHERE yourField LIKE & '" search & "'"

Now thats the basics. It looks like you are going to want to search 3 distinct fields for distinct information. So I would set something like this up for your case.

A drop down list for the year, and maybe even the other two fields. Then declare a variable for each of these and assign a value to each of the variables
Dim srchYear : srchYear = Request.Form("year")
Dim strColour : strColour = "%" & Request.Form(''colour") & "%"
Dim strModel : strModel = Request.Form("model")

Then depending on how you have the database column datatypes set up your select statement would look somthing like this
"SELECT * FROM yourTable WHERE [year] = " & srchYear & " AND colour LIKE '" & strColour & "' AND model = '" & strModel & "'"

Now the [ ] around year is because year is a reserved word in MS Access so if you name a field that, you use the square brackets to tell Access you are searching a column with that name. I am guessing the year field is of the number datatype and the others are of the text or memo datatypes. Any time you have a text datatype your WHERE statement needs to enclose the variable in ' ' single quotes.

That should give you a pretty good start. Now use what you learn on the W3Schools website and go from there.