Re: ado recordset.recordcount has value 0

From: Paul Baker [MVP, Windows - SDK] (paulb_at_online.rochester.rr.com)
Date: 02/24/04


Date: Tue, 24 Feb 2004 10:52:45 -0500

Yes, it is better to use BOF and EOF. Using the RecordCount property forces
it to count how many records there is, which is very inefficient and could
take a long time. This could bog down your server or no good reason. You
don't care how many records there are, you just care if the RecordSet is
empty. It is also true that some providers don't support it.

The code below doesn't work if you have records and you're already at the
BOF or EOF. For example, you repeatedly go to the next record until EOF. In
this situation, BOF is False and EOF is True. The condition in the If
statement is False and so it executes the else clause "Recorset don't have
records", but actually the RecordSet does have records.

Code that functions in all situations and is slightly cleaner is:

If rs.BOF and rs.EOF Then
  ' RecordSet is empty
Else
  ' RecordSet is not empty
End If

Paul

"Victor Koch" <v i c t o r (arroba)correo(punto)waldbott(punto)com(punto)ar>
wrote in message news:%23xYDKou%23DHA.2664@TK2MSFTNGP09.phx.gbl...
> Hi pherms, i believe is better use BOF and EOF properties to know if a
> recordset have records.
>
> Rs.Open "SELECT ................"
>
> If Rs.BOF = False And Rs.EOF = False Then
> ' Recordset have records
> else
> ' Recordset don't have records
> endif
>
> RecordCount Property is not supported for all providers.
>
> --
> Víctor Koch From Argentina.
>
>
> "pherms" <pherms@planet.nl> escribió en el mensaje
> news:63B09C44-6CE7-440A-8A1A-BE353A3616A6@microsoft.com...
> > I have this really weird problem.
> > When I query a database with a string, which I know will return only one
> record, by using an asp page, the recordcount object of the
adodb.recordset
> has value 0. I do know that the sql query I use is ok, because I tested it
> in my database app.
> >
> > I use Windows 2003 server as the asp platform and I use mysql 4.0.18 ad
> the database.
> >
> > Please can anyone help me? It's dirving me crazy!
>
>



Relevant Pages