Web Developer's Virtual Library: Encyclopedia of Web Design Tutorials, Articles and Discussions


WDVL Newsletter

Active Server Pages
JSP/Java Servlets
Microsoft SQL Server
Daily Backup
Dedicated Servers
Streaming Audio/Video
24-hour Support    

jobs.webdeveloper.com

Hiermenus


e-commerce
Partner With Us















Developer Channel
FlashKit.com
JavaScript.com
JavaScriptSource
Developer Jobs
ScriptSearch
StreamingMediaWorld
Web Developer's Journal
Web Developer's Virtual Library
WebDeveloper.com
Webreference
Web Hosts
XMLfiles.com

internet.com
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers


Building a Table - Page 8

November 27, 2000

Let's use the Clothier database again, to create a table that shows the Name and department of the first five items.

<TITLE>2726-03-SimpleRS TIO Building a Table
	of the First Five Clothing Items</TITLE>
</HEAD>
<BODY>
<H1>Chapter 3 Simple Recordsets<BR>
Try It Out - <BR>
Building a Table of <BR>
the First Five Clothing Items</h1>
<%
dim oRSc
dim iRowCounter
set oRSc=server.CreateObject("adodb.recordset")
oRSc.open "items", "DSN=clothier"
oRSc.MoveFirst

Response.Write "<TABLE BORDER='1'>"
For iRowCounter = 1 to 5
  Response.Write "<TR><TD>" & oRSc("ItemName") & "</TD>"
  Response.Write "<TD>" & oRSc("ItemDepartment") & "</TD></TR>"
  oRSc.MoveNext
next
%>
</TABLE></BODY</html>
The above code produces the following screen.

Example 3

How It Works - Building a Table of the First Five Clothing Items

The following lines create the recordset and ensure that we are positioned at the first record:

dim oRSc
dim iRowCounter
set oRSc=server.CreateObject("adodb.recordset")
oRSc.open "items", "DSN=clothier"
oRSc.MoveFirst
Then we begin to write the table to the web page. First, we write the <TABLE> tag, which belongs outside the loop:
Response.Write "<TABLE BORDER='1'>"
Now we can loop through the first five records. Note that, like all For...Next Loops we need a counter to keep track of the number of loops that have been performed. In each loop we write the open row tag <TR> then the tags and data for the two cells in the two columns:
For iRowCounter = 1 to 5
  Response.Write "<TR><TD>" & oRSc("ItemName") & "</TD>"
  Response.Write "<TD>" & oRSc("ItemDepartment") & "</TD></TR>"
  oRSc.MoveNext
next
%>
And then we place the table close tag outside of the loop as follows.
</TABLE>
</BODY</html>

Building Tables with Data - Page 7
Beginning ASP Databases
Reading All of the Records (with EOF) - Page 9


Up to => Home / Authoring / ASP / BeginningASPDatabases




Jupiter Online Media: internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and Jupiter Online Media

Jupitermedia Corporate Info


Legal Notices, Licensing, & Permissions, Privacy Policy.

Web Hosting | Newsletters | Tech Jobs | Shopping | E-mail Offers