Try It Out - Table Using EOF and a Counter - Page 11
November 27, 2000
Now we can improve on the last code listing by adding a numbering
column and a note on the number of sailors at the bottom. Later
we will learn the use of the recordcount property,
but for now we will use a counter variable.
<%
dim oRSeofc
set oRSeofc=Server.createObject("ADODB.recordset")
oRSEOFc.Open "People", "DSN=sailors"
oRSeofc.MoveFirst
Response.Write "<TABLE BORDER='1'>"
Dim PersonCounter
PersonCounter = 0
Do while NOT oRSeofc.EOF
PersonCounter =PersonCounter + 1
Response.Write "<TR><TD>" & PersonCounter & "</TD>"
Response.Write "<TD>" & oRSeofc("PeopleNameFirst") & "</TD>"
Response.Write "<TD>" & oRSeofc("PeopleNameLast") & "</TD></TR>"
oRSeofc.MoveNext
Loop
Response.Write "</TABLE><BR>"
Response.Write PersonCounter & " Sailors in this list"
%>
How it Works - Sailors Table with EOF an
The set up of the recordset is the same as the last code listing,
but now we dim another variable for the purpose of keeping count
of the people and initialize that to zero:
Dim PersonCounter
PersonCounter = 0
Now when we do our loops we start by increasing that
PeopeCounter by 1 and printing that in its own cell.
Then we finish off the row as before.
Do while NOT oRSeofc.EOF
PersonCounter =PersonCounter + 1
Response.Write "<TR><TD>" & PersonCounter & "</TD>"
Response.Write "<TD>" & oRSeofc("PeopleNameFirst") & "</TD>"
Response.Write "<TD>" & oRSeofc("PeopleNameLast") & "</TD></TR>"
oRSeofc.MoveNext
Loop
Response.Write "</TABLE>"
%>
Try It Out - Table Using EOF - Page 10
Beginning ASP Databases
A Trap With Recordsets and Tables - Page 12
|