home *** CD-ROM | disk | FTP | other *** search
- <%
- '*******************************************************
- '* ASP 101 Sample Code - http://www.asp101.com *
- '* *
- '* This code is made available as a service to our *
- '* visitors and is provided strictly for the *
- '* purpose of illustration. *
- '* *
- '* Please direct all inquiries to webmaster@asp101.com *
- '*******************************************************
- %>
-
- <%
- ' Declare our variables... always good practice!
- Dim cnnSimple ' ADO connection
- Dim rstSimple ' ADO recordset
- Dim strDBPath ' path to our Access database (*.mdb) file
-
-
- ' MapPath of virtual database file path to a physical path.
- ' If you want you could hard code a physical path here.
- strDBPath = Server.MapPath("db_scratch.mdb")
-
-
- ' Create an ADO Connection to connect to the scratch database.
- ' We're using OLE DB but you could just as easily use ODBC or a DSN.
- Set cnnSimple = Server.CreateObject("ADODB.Connection")
-
- ' This line is for the Access sample database:
- 'cnnSimple.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & ";"
-
- ' We're actually using SQL Server so we use this line instead:
- cnnSimple.Open Application("SQLConnString")
-
-
- ' Execute a query using the connection object. It automatically
- ' creates and returns a recordset which we store in our variable.
- Set rstSimple = cnnSimple.Execute("SELECT * FROM scratch")
-
-
- ' Display a table of the data in the recordset. We loop through the
- ' recordset displaying the fields from the table and using MoveNext
- ' to increment to the next record. We stop when we reach EOF.
- %>
- <TABLE BORDER="1">
- <%
- Do While Not rstSimple.EOF
- %>
- <TR>
- <TD><%= rstSimple.Fields("id").Value %></TD>
- <TD><%= rstSimple.Fields("text_field").Value %></TD>
- <TD><%= rstSimple.Fields("integer_field").Value %></TD>
- <TD><%= rstSimple.Fields("date_time_field").Value %></TD>
- </TR>
- <%
-
- rstSimple.MoveNext
- Loop
- %>
- </TABLE>
- <%
- ' Close our recordset and connection and dispose of the objects
- rstSimple.Close
- Set rstSimple = Nothing
- cnnSimple.Close
- Set cnnSimple = Nothing
-
- ' That's all folks!
- %>
-