Search w3schools.com:

SHARE THIS PAGE

ASP Classic - Adding a Database


Learn ASP Classic by building a web site from scratch.

Part III: Adding a Database.


What We Will Do

In this chapter we will:

  • Create a page to list data from a database

Displaying Data from Database

With ASP, you can easily display data from a database.

You can connect to an existing database, or create a new database from scratch.

In this example we will connect to an existing Microsoft Access database.

You can download the database from this link: Northwind.zip


Adding a Customers Page

In the "DemoASP" folder, create a new ASP file named "Customers.asp".

Put the following code inside the file:

Customers.asp

<!DOCTYPE html>

<html>
<head>
  <title>ASP Demo</title>
  <link href="Site.css" rel="stylesheet">
</head>

<body>

<div id="main">
<h1>Customers</h1>
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open("C:\WebData\Northwind.mdb")
set rs = Server.CreateObject("ADODB.recordset")
rs.Open "Select CompanyName, City, Country FROM Customers", conn
%>
<table border="1">
<tr><th>Name</th><th>City</th><th>Country</th></tr>
<%do until rs.EOF%>
<tr>
<%for each x in rs.Fields%>
<td>
<%Response.Write(x.value)%>
</td>
<%next%>
</tr>
<%
rs.MoveNext
loop
%>
</table>
<%
rs.close
conn.close
%>

<!-- #include="Footer.inc" -->
</div>

</body>
</html> 

Run example »


Congratulations

You have added a database to your web project.




W3Schools Certification

W3Schools' Online Certification

The perfect solution for professionals who need to balance work, family, and career building.

More than 10 000 certificates already issued!

Get Your Certificate »

The HTML Certificate documents your knowledge of HTML.

The HTML5 Certificate documents your knowledge of advanced HTML5.

The CSS Certificate documents your knowledge of advanced CSS.

The JavaScript Certificate documents your knowledge of JavaScript and HTML DOM.

The jQuery Certificate documents your knowledge of jQuery.

The XML Certificate documents your knowledge of XML, XML DOM and XSLT.

The ASP Certificate documents your knowledge of ASP, SQL, and ADO.

The PHP Certificate documents your knowledge of PHP and SQL (MySQL).

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]