home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 4 / hacker04 / 04_HACK04.ISO / src / ASP / database_simple.asp < prev    next >
Encoding:
Text File  |  2001-06-08  |  2.2 KB  |  70 lines

  1. <%
  2. '*******************************************************
  3. '*     ASP 101 Sample Code - http://www.asp101.com     *
  4. '*                                                     *
  5. '*   This code is made available as a service to our   *
  6. '*      visitors and is provided strictly for the      *
  7. '*               purpose of illustration.              *
  8. '*                                                     *
  9. '* Please direct all inquiries to webmaster@asp101.com *
  10. '*******************************************************
  11. %>
  12.  
  13. <%
  14. ' Declare our variables... always good practice!
  15. Dim cnnSimple  ' ADO connection
  16. Dim rstSimple  ' ADO recordset
  17. Dim strDBPath  ' path to our Access database (*.mdb) file
  18.  
  19.  
  20. ' MapPath of virtual database file path to a physical path.
  21. ' If you want you could hard code a physical path here.
  22. strDBPath = Server.MapPath("db_scratch.mdb")
  23.  
  24.  
  25. ' Create an ADO Connection to connect to the scratch database.
  26. ' We're using OLE DB but you could just as easily use ODBC or a DSN.
  27. Set cnnSimple = Server.CreateObject("ADODB.Connection")
  28.  
  29. ' This line is for the Access sample database:
  30. 'cnnSimple.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & ";"
  31.  
  32. ' We're actually using SQL Server so we use this line instead:
  33. cnnSimple.Open Application("SQLConnString")
  34.  
  35.  
  36. ' Execute a query using the connection object.  It automatically
  37. ' creates and returns a recordset which we store in our variable.
  38. Set rstSimple = cnnSimple.Execute("SELECT * FROM scratch")
  39.  
  40.  
  41. ' Display a table of the data in the recordset.  We loop through the
  42. ' recordset displaying the fields from the table and using MoveNext
  43. ' to increment to the next record.  We stop when we reach EOF.
  44. %>
  45. <TABLE BORDER="1">
  46. <%
  47. Do While Not rstSimple.EOF
  48.     %>
  49.     <TR>
  50.         <TD><%= rstSimple.Fields("id").Value %></TD>
  51.         <TD><%= rstSimple.Fields("text_field").Value %></TD>
  52.         <TD><%= rstSimple.Fields("integer_field").Value %></TD>
  53.         <TD><%= rstSimple.Fields("date_time_field").Value %></TD>
  54.     </TR>
  55.     <%
  56.  
  57.     rstSimple.MoveNext
  58. Loop
  59. %>
  60. </TABLE>
  61. <%
  62. ' Close our recordset and connection and dispose of the objects
  63. rstSimple.Close
  64. Set rstSimple = Nothing
  65. cnnSimple.Close
  66. Set cnnSimple = Nothing
  67.  
  68. ' That's all folks!
  69. %>
  70.