Click here to Skip to main content
14,176,439 members
Click here to Skip to main content
Add your own
alternative version


24 bookmarked
Posted 2 Jun 2002

Display records in a table using ASP

, 2 Jun 2002
Rate this:
Please Sign up or sign in to vote.
A beginners guide to displaying records from a database in a table using ASP


The following code will allow you to display the contents of a database table in an HTML table. The HTML table is built dynamically as the records are pulled out of the database. Minimal changes are necessary if you copy and paste this code - basically just change the DSN, table and field names. Note this example has an inner table for formatting purposes, but it is not necessary.


<%@ Language="VBScript%">



<title>Display all Records</title>




strSQL = "Select * from TableName;" 'create SQL string (where clauses etc 

'should be added according to what you would like displayed)

SET DbObj = Server.CreateObject("ADODB.Connection") 'set up the 

'ADO connection

DbObj.Open "DSN=DSNName","username","password" 'open the connection to 

'the database, using DSN - set up the DSN in your control panel

SET oRs = DbObj.Execute(strSQL) 'Execute the SQL statement

on error resume next
<table border="1" width="100%" bordercolor="#00FFFF">
<td width="35%">
<table border="0" width="96%">
<td width="100%"><font color="#000080" size="4">
Display field description here: <% = oRs.Fields("FieldName") %></td>
<font color="#000080" size="4">
<td width="65%">  <% = oRs.Fields("FieldName") %></td></font>
<% oRs.MoveNext %>
<% Loop %> 'Go to the next record if not end of file
<% DbObj.Close 'Close the database connection
SET DbObj = Nothing 'Clean up after yourself


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Megan Forbes
Web Developer
Australia Australia
I am a South African web / SQL developer currently spending my time as a mum. My other passion is photography and have put a small portfolio up here[^]

You may also be interested in...


Comments and Discussions

Questionweb based search Application Pin
Mailk Kashif Zulfiqar20-Apr-07 1:01
memberMailk Kashif Zulfiqar20-Apr-07 1:01 
Generaldb connection Pin
benet fernandes17-Mar-07 23:10
memberbenet fernandes17-Mar-07 23:10 
QuestionPlease give me a way for display pictures which store in DB Access 2003 by &quot;OLE object&quot;? Pin
tuyenhnp25-Sep-05 16:50
membertuyenhnp25-Sep-05 16:50 
GeneralHandy Article, Megan! Pin
Roger Wright26-Jul-04 4:23
professionalRoger Wright26-Jul-04 4:23 
GeneralCode won't work using SunOne asp Pin
Anonymous10-Mar-04 22:31
memberAnonymous10-Mar-04 22:31 
GeneralNewB suggestion from a NewB Pin
paxtonk24-Nov-03 11:23
memberpaxtonk24-Nov-03 11:23 
GeneralJust a suggestion..... Pin
Christian Graus3-Jun-02 12:02
protectorChristian Graus3-Jun-02 12:02 
GeneralRe: Just a suggestion..... Pin
Nish Nishant4-Jun-02 0:01
sitebuilderNish Nishant4-Jun-02 0:01 
GeneralRe: Just a suggestion..... Pin
Jon Sagara4-Jun-02 1:43
memberJon Sagara4-Jun-02 1:43 
GeneralRe: Just a suggestion..... Pin
Nish Nishant4-Jun-02 17:32
sitebuilderNish Nishant4-Jun-02 17:32 
GeneralRe: Just a suggestion..... Pin
Megan Forbes24-Sep-02 1:19
memberMegan Forbes24-Sep-02 1:19 
GeneralRe: Just a suggestion..... Pin
Nish Nishant13-Oct-03 19:44
sitebuilderNish Nishant13-Oct-03 19:44 
JokeRe: Just a suggestion..... Pin
uk_rain_sky11-Mar-06 3:03
memberuk_rain_sky11-Mar-06 3:03 
GeneralRe: Just a suggestion..... Pin
Nish Nishant12-Mar-06 12:21
sitebuilderNish Nishant12-Mar-06 12:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web03 | 2.8.190525.1 | Last Updated 3 Jun 2002
Article Copyright 2002 by Megan Forbes
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid