ASP.Net Tutorials
Display Records from an Access Database
<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" %>
<%@ Import Namespace="System.Data.OleDb" %>
<!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=iso-8859-1" />
<title>Display Quotes</title>
<style type="text/css">
<!--
body {background: #f0f0f0;}
#main_container {background:#fff; margin:auto; width: 550px; border: 4px solid #999; padding: 20px;}
.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>
-->
</style>
<script runat="server">
sub Page_Load
Dim my_connection, my_query, my_db_command
my_connection = New OleDbConnection ("Provider=Microsoft.Jet.OLEDB.4.0; data source=" & server.mapPath("/dir/quotes.mdb"))
my_connection.open()
my_query = "SELECT * FROM my_quotes"
my_db_command = New OleDbCommand (my_query, my_connection)
Dim my_data_reader As OleDbDataReader
my_data_reader = my_db_command.ExecuteReader()
Do While my_data_reader.Read()
my_records_label.text & = "<div class='quote'>" & my_data_reader("quote") & "</div>"
my_records_label.text & = "<div class='author'>" & my_data_reader("first_name") & " "
my_records_label.text & = my_data_reader("last_name") & "</div>"
loop
my_data_reader.nextResult()
my_db_command.dispose()
my_data_reader.close()
my_connection.close()
end sub
</script>
</head>
<body>
<div id="main_container">
<form id="my_form" runat="server">
<asp:label id="my_records_label" runat="server" />
</form>
</div>
</body>
</html>