Form to database Part 2

The code below will show all the records that you have entered into your form. (See Part 1)

Call our file 'show_records.asp'.

<%@ Language="VBScript" %>
<% Option Explicit %>
<html>
<head>
<title>Form to database - showing records</title>
</head>
<body>
<%
'declare your variables

Dim connection, recordset
Dim sSQL, sConnString

'declare SQL statement that will query the database
sSQL="SELECT * FROM Users_tbl"

'create an ADO connection and recordset object
Set connection = Server.CreateObject("ADODB.connection")
Set recordset = Server.CreateObject("ADODB.Recordset")

'define the connection string, specify database
'driver and the location of database

sConnString="PROVIDER=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Server.MapPath("Users.mdb")

'Open the connection to the database
Connection.Open sConnString

'Open the recordset object, executing the SQL
Recordset.Open sSQL, Connection

'Looping through the records until the end of the records
Do while Not recordset.eof
Response.Write "Name : " & recordset("name") & "<br>"
Response.Write "Email : " & recordset("email") & "<br>"
Response.Write "Comments : " & recordset("comments") & "<br><br>"
'move on to the next record
recordset.MoveNext
loop

'Now close the recordset and the connection object
recordset.Close
Set recordset = Nothing
connection.Close
Set connection = Nothing
%>
</body>
</html>


Previous: INSERT Form Content to Database (Part 1)

Advertisements



MembersPro

MembersPro PayPal - ASP Membership software

Plug and play ASP membership script that integrates with PayPal to let you charge recurring membership fees.

Get your best asp web hosting provider now and save 25%