ASP Tutorials
Display records from an SQL table
<%@ language="VBScript" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>ASP Test</title>
<style type="text/css">
<!
.quote {background: #F0F0E1; padding: 1em; font: 19px Georgia, Arial, "Times New Roman", Times, serif;}
.author {text-align: right; margin-bottom: 2em; font: 10px Verdana, Geneva, sans-serif;}
-->
</style>
</head>
<body>
<%
dim myDatabaseConnection
dim myServerConnection
dim myDatabaseRecord
dim myDatabaseQuery
myServerConnection="DRIVER={SQL Server}; SERVER=127.0.0.0; UID=xxxxxxxx; PWD=xxxxxxxx; DATABASE=xxxxxxxx"
myDatabaseQuery="SELECT * FROM my_quotes"
set myDatabaseConnection = Server.CreateObject("ADODB.Connection")
set myDatabaseRecord = Server.CreateObject("ADODB.recordset")
myDatabaseConnection.open myServerConnection
myDatabaseRecord.open myDatabaseQuery, myDatabaseConnection
if myDatabaseRecord.eof then
response.write ("No records found.")
else
do while not myDatabaseRecord.eof
response.write "<div class=""quote"">" & myDatabaseRecord("quote") & "</div>"
response.write "<div class=""author"">" & myDatabaseRecord("first_name") & " "
response.write myDatabaseRecord("last_name") & "</div>"
myDatabaseRecord.moveNext
loop
end if
myDatabaseRecord.close
set myDatabaseRecord=nothing
myDatabaseConnection.close
set myDatabaseConnection=nothing
%>
</body>
</html>