Looping through a database

Results 1 to 2 of 2

Thread: Looping through a database

  1. #1
    Join Date
    Dec 1969

    Default Looping through a database

    I am using an ASP page using VBscript to loop through a recordset generated by a stored procedure. When the recordset is empty if returns the ugly ADODB error message, Is my if then loop to check messing up? Here is the code:<BR>&#060;%<BR> do while not RS.EOF<BR> <BR> If (RS.EOF) then <BR> Response.Write "No Outstanding Requests"<BR> else<BR>%&#062;<BR> ...DYNAMIC HTML TABLE POPULATION FROM RS...<BR>&#060;% <BR> end if<BR><BR>RS.MoveNext<BR>Loop<BR>%&#062;<BR>

  2. #2
    Join Date
    Dec 1969

    Default Code doesn't make much sense

    Since your loop is exited when RS.EOF is reached, how will you ever *get* to the code inside the loop where RS.EOF is true? Can&#039;t happen.<BR><BR>Instead:<BR><BR>&#060;%<BR>If RS.EOF Then<BR> ...<BR>End If<BR><BR>Do While Not RS.EOF<BR> ...<BR> RS.MoveNext<BR>Loop<BR>%&#062;<BR><BR>If you go an EOF from your SQL query, then the message gets displayed (via the IF) and the loop never runs (because the WHILE if false even before first time through).<BR><BR>Some people code that as:<BR><BR>&#060;%<BR>If RS.EOF Then<BR> ...<BR>Else<BR><BR> Do While Not RS.EOF<BR> ...<BR> RS.MoveNext<BR> Loop<BR><BR>End If<BR>%&#062;<BR><BR>Which is fine, but kind of silly extra code, since the DO loop *will* take care of the EOF condition, just fine.<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts