[thelist] Check for empty record set?

Ken Schaefer ken at adOpenStatic.com
Thu Jun 19 20:40:57 CDT 2003


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: From: "Koutoulas, Pete" <PKOUTOUL at Fayette.k12.ky.us>
:
: If you just returned a record set and EOF is true, then you know
: no records were returned, assuming that your record set starts
: at the first record, which is true for most data providers in most
: situations. However, in those cases were you cannot depend on
: starting at the first record, then there is some ambiguity in using
: a test for EOF alone (or BOF alone).
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

If you check the ADO documentation, you will find in all cases that, where
you've just opened a recordset, and no records are returned, both .EOF and
.BOF are set to true. You only need to check for one, or the other.

In any case, one should be using .GetRows or .GetString in most cases,
rather than carrying around a Recordset object, so you'd do:

<%
Set objRS = objCommand.Execute ' (or objConn.Execute)
If not objRS.EOF then arrResults = objRS.getRows

objRS.Close
Set objRS = Nothing
%>

Cheers
Ken

----- Original Message ----- 
From: "Koutoulas, Pete" <PKOUTOUL at Fayette.k12.ky.us>
To: <thelist at lists.evolt.org>
Sent: Thursday, June 19, 2003 11:59 PM
Subject: RE: [thelist] Check for empty record set?


: On Thursday, June 19, 2003 9:42 AM, Stephen Caudill wrote:
:
: > I noted that it seems to be the consensus to specify:
: >  if not (rs.eof and rs.bof) then
: >
: > rather than just
: >  if not rs.eof
: >
: > What is the advantage, practically, of one over the other (other than
: > specificity)?
:
: BOF is true if the current record is before the first record. EOF is true
if
: the current record is past the last record.
:
: If you just returned a record set and EOF is true, then you know no
records
: were returned, assuming that your record set starts at the first record,
: which is true for most data providers in most situations. However, in
those
: cases were you cannot depend on starting at the first record, then there
is
: some ambiguity in using a test for EOF alone (or BOF alone).
:
: Since EOF and BOF can only be both true if no records were returned, that
is
: the safest and most universal test for an empty record set.



More information about the thelist mailing list