<%
'
'
' Purpose: Example of OLEDB listing of Access database table
'
' Version: 1.0.0
'
' Date: 3/4/2004
'
' Name: WebClubMemberSimpleList.asp
'
' Changes:
' 1. Original programming
'
' Programmer: Lon Hosford lon @ hosfordusa.com
'
'
'
%>
<html>
<body>
<%
'
' Use the ASP Server class CreateObject action to gain access
' to the ADODB library on the web server to
' create a connection object from the ADODB library
' Connection class.
' A connection object contains all data and actions for a database
' connection via various techniques.
' We are using the name oConn to represent our connection object.
'
Set oConn = Server.CreateObject("ADODB.Connection")
'
' Use a variable to represent the connection string required
' by the connection object. The variable is optional and
' is a discretion to make futher lines in the code needing this
' easier to read and maintain.
' The connection string is made of three parts.
' 1. PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=
' 2. The server path to our Access database
' Use the ASP Request object
' ServerVariables("APPL_PHYSICAL_PATH")
' to dynamically get the database path.
' 3. The name of the access database
ConnString = "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE="
ConnString = ConnString & Request.ServerVariables("APPL_PHYSICAL_PATH")
ConnString = ConnString & "WebMaster.mdb"
'
'
' Testing feedback of the ConnString variable contents.
'
Response.Write "<center>Connection String = " & ConnString & "</center>"
'
' Use the Connection object open action to establish a connection
' to the Access database.
'
oConn.Open ConnString
'
' If needed uncomment next line to see any error messages
' that might be suppressed.
'Response.Write err.number & "- " & err.description
'
' Use a variable to represent the SQL statement.
' The variable is optional and is a discretion to make futher
' lines in the code needing this easier to read and maintain.
' Select all fields and all records from the table WebClubMembers
SQL = "Select * From WebClubMembers"
'
' Testing feedback of the SQL variable contents.
'
Response.Write "<center>SQL Statement = " & SQL & "</center>"
'
' Use the Connection object execute action to submit the
' SQL statement to the database and receive an ADO Recordset
' object back with a pointer to the first record.
Set oRs = oConn.Execute (SQL)
'
'
' Create the table heading using Html.
%>
<table border = "1" align="center">
<tr>
<td>
<b>Name</b>
</td>
<td>
<b>Email</b>
</td>
<td>
<b>Web Address</b>
</td>
</tr>
<%
' Below uses a loop statement
' to repeat rows in the table for each record.
' Html and script is intermingled to make the
' best of use of each versus using all script
' ASP Response object Write actions to
' return the Html tags.
'
' The beginning of the loop is
' do while not oRs.Eof
' The end of the loop is
' loop
' The loop repeats the lines between while
' the ADO RecordSet object oRS Eof value is true
'
' The ADO RecordSet object moveNext action moves
' to next record in the record set ech loop iteration.
'
' The ADO RecordSet Fields collection allows access to
' field object using field names in the recordset.
' The field objects have a value property to give
' the data in that field.
'
'
' After the loop the ADO RecordSet object
' close method is issued as standard operating
' procedure of good practices.
'
%>
<% Do While Not oRs.Eof %>
<tr>
<td>
<%= oRs.Fields("FirstName").Value & " " %>
<%= oRs.Fields("LastName").Value %>
</td>
<td>
<%= oRs.Fields("EmailAddress").Value %>
</td>
<td>
<a href = "<%= oRs.Fields("WebAddress").Value %>">
<%= oRs.Fields("WebAddress").Value %>
</a>
</td>
</tr>
<% oRs.MoveNext
Loop%>
<% oConn.Close %>
</table>
</body>
</html>