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.
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
|