Forum Moderators: open

Message Too Old, No Replies

Using a form control to perform a query

Access as data source & ASP as language

         

Darkelve

9:34 am on Dec 23, 2005 (gmt 0)

10+ Year Member



I created a simple Access database (ID - primary key, name, address, postalcode).

Then I made a DNS-less connection from an ASP page to display the records in a list.

My objective is to provide visitors with a simple form, where they can type the postal code. Then all records corresponding to the postal code in the Access database should be displayed. How can I do this?

The DB content is not confidential. It is expected to fill up with 2000 to 5000 records. Maybe 10 000 as the upper limit. A few dozens of people might access it simultaneously when visitor traffic is high. So another question is if this solution is acceptable for the situation, as I heard about data corruption and things like that with Access.

Below the code I have up to now.

Darkelve


<% @ LANGUAGE=VBScript %>
<% option explicit %>
<%

'First you must define the variables you are going to use
Dim accessdb
Dim ConnectionString
Dim Connection
Dim strQuery
Dim RS

'Enter the location of your database
accessdb=Server.MapPath("test.mdb")

'Now we will build the dsn-less connection
ConnectionString="DRIVER={Microsoft Access Driver (*.mdb)};"
ConnectionString=ConnectionString & "DBQ=" & accessdb

'Create the ADO Connection object set
Set Connection = Server.CreateObject("ADODB.Connection")
Connection.Open ConnectionString

'Create an SQL query string
strQuery = "SELECT * FROM voorverkooppunten"

' Execute the SQL query string
Set RS = Connection.Execute(strQuery)

'Show the contents of the table
Response.Write ("<ul class='longlist'>")
While Not RS.EOF
Response.Write ("<li>")
Response.Write RS("naam") & (" - ") & RS("adres")
Response.Write "</li>"
RS.MoveNext
Wend
Response.Write ("</ul>")

'close the connection
RS.Close : Connection.Close
set RS = Nothing : set Connection = Nothing
%>

Darkelve

12:23 pm on Dec 23, 2005 (gmt 0)

10+ Year Member



Well, I'm not really used to ASP programming, but found a solution myself:

<%
'First you must define the variables you are going to use
Dim accessdb
Dim ConnectionString
Dim Connection
Dim strQuery
Dim RS
dim postcodevalue
dim dynamicrequest
postcodewaarde=Request.QueryString("code")

dynamicrequest=("SELECT * FROM vvk WHERE postcode=") & (postcodevalue)

'Enter the location of your database
accessdb=Server.MapPath("test.mdb")

'Now we will build the dsn-less connection
ConnectionString="DRIVER={Microsoft Access Driver (*.mdb)};"
ConnectionString=ConnectionString & "DBQ=" & accessdb

'Create the ADO Connection object set
Set Connection = Server.CreateObject("ADODB.Connection")
Connection.Open ConnectionString

'Create an SQL query string
strQuery = dynamicrequest

' Execute the SQL query string
Set RS = Connection.Execute(strQuery)

'Show the contents of the table
Response.Write ("<ul class='longlist'>")
While Not RS.EOF
Response.Write ("<li>")
Response.Write RS("naam") & (" - ") & RS("adres") & (" - ") & RS("postcode")
Response.Write "</li>"
RS.MoveNext
Wend
Response.Write ("</ul>")

'close the connection
RS.Close : Connection.Close
set RS = Nothing : set Connection = Nothing
%>

So this post is solved.

steve

3:18 pm on Dec 23, 2005 (gmt 0)

10+ Year Member



ConnectionString="DRIVER={Microsoft Access Driver (*.mdb)};"

Although this driver will work it is no longer supported by Microsoft.

Consider using "Provider=Microsoft.Jet.OLEDB.4.0;" instead.