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


Reading All of the Records (with EOF) - Page 9

November 27, 2000

By building a table that displays the first five records of a recordset, we get some idea of the techniques and practice with the HTML codes for tables. However, most of the time you will have no idea of how many records are in your recordset - so you won't know how many times to repeat the loop. ADO provides a way to test whether you are at the end of the records, and thus should stop building rows. The property to use is called EOF (which is short for 'End Of File'). The recordset object's EOF property evaluates to True after you have moved beyond the last row. Take a look at the following test:

   Do while NOT oRSp.EOF
     Response.Write oRSp("PeopleNameLast") & "<BR>"
     oRSp.MoveNext
   Loop
The above code is a little tricky to understand if you have never used this construction before, so refill the coffee cup and follow this closely:
  1. The way the DO WHILE works, in general, is that before each cycle of the loop ASP-ADO checks the test expression on the DO WHILE line. If the test is True, ASP-ADO will perform the loop again.
  2. But we are using the value of the EOF property of oRSp as the test object. rs.EOF is False when we are still in the data and True when we are done with the records. That is the opposite of what we want for the DO WHILE. We want to continue looping when the rs.EOF is False (we are in middle of records) and we want to stop looping when EOF is True (at end of records).
  3. VBScript provides us with the word NOT to reverse the value of the rs.EOF. Now when rs.EOF returns a False (in middle of records) NOT changes that into a True and the loop is performed again. When the rs.EOF is set to True (at end of records), NOT turns that into a False and the looping stops.
Remember that every loop must have a way to end. In this case we include the rs.MoveNext line to tell ADO's cursor to go to the next record. Eventually ASP-ADO will move beyond the last record and then the rs.EOF will turn to true. Our test will "NOT" that True into a False and end the loop right there at the end of the records.

Common Errors

  • Leaving the "RS." off of rs.EOF
  • Leaving RS.MoveNext out of the loop
  • Leaving out the "NOT" from the expression
  • Putting <TABLE> inside the loop
  • Leaving out </TABLE>.

Building a Table - Page 8
Beginning ASP Databases
Try It Out - Table Using EOF - Page 10


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