Categories

Tools

bitdefender

1&1 Web Hosting

How to read and display data from an Access database with ASP, using ADODB.Connection


This ASP code sample shows how to read and display data from an Access database with ASP.

Code:

<html>
<head>
  <title>List of Customers - MdmSoft</title>
  <style type="text/css">
  	#customers { 
	border:1px solid #777;
	border-collapse:collapse;		
	font-family: "verdana";
	font-size:14px;
	}
	
	th {
	background-color:#CCCCCC; 
	color:#0066FF;
	text-align:left;
	}
	
	tr {
	border:1px solid #777;
	}
  </style>
</head>
<body>
<div>
<%
	' Create a Connection
	Dim conn
	Set conn = Server.CreateObject("ADODB.Connection")
	
	' Open the connection
	conn.Open "driver={Microsoft Access Driver (*.mdb)}; dbq=" & Server.MapPath("App_Data/Northwind.mdb")
	
	' Create a Recordset
    Dim rsCustomers 
	set rsCustomers = server.createobject("ADODB.Recordset")
    
	' Create a SQL query
	Dim Sql
	Sql = "SELECT * FROM spSelectCustomers"

	' Open the Recordset
	rsCustomers.open Sql, conn, 3 , 3
	
	' Create a HTML table
    Response.write( "<table id='customers' border='0'>" )
	Response.write( "<th>Name</th>")
	Response.write( "<th>Company</th>")
	Response.write( "<th>City</th>")
	
	' Loop the Recordset and print the information
	Do While not rsCustomers.EOF
		Response.write( "<tr>")
			Response.write( "<td>" & rsCustomers.Fields(0) & "</td>")
			Response.write( "<td>" & rsCustomers.Fields(1) & "</td>")
			Response.write( "<td>" & rsCustomers.Fields(2) & "</td>")
		Response.write( "<tr>")
		rsCustomers.MoveNext
	Loop
	
	Response.write( "</table>" )
		
	' Close all 
	rsCustomers.close
	conn.close
%>
</div>
</body>
</html>

Result:

 How to read and display data from an Access database with ASP, using ADODB.Connection

Posted in ASP by MdmSoft

If our work has been of help, you can help us with a small donation...
Our programmers will thank you!



All information contained in this web site are the property of MdmSoft. The information is provided "as is", MdmSoft will not be liable for any misuse of the code contained in these pages, nor can it be for inaccuracies, grammatical errors or other factors that may have caused damage or lost earnings. MdmSoft is not responsible for the content of comments posted by users.
The examples in this area have the educational and demonstration purposes only, and may be copied only for your reference, but cannot be used for commercial purposes, or for any other purpose, without the express written consent of MdmSoft.
MdmSoft also reserves the right to change, without notice, to your liking this web site, the pages and its sections, and may suspend temporarily or definitely the various services included on this site.
While using this site, you agree to have read and accepted our Terms of Service and Privacy Policy.