[thelist] ASP count

Paul Cowan evolt at funkwit.com
Sun Nov 3 17:12:01 CST 2002

rudy wrote:
> in coldfusion one would simply use the value of otherquery.RecordCount, a
> special variable made just for this purpose, and ASP has a similar
> (i don't know what it is, but i know it exists)

otherquery.RecordCount will do nicely in ASP, funnily enough... but see

> even if a special variable didn't exist, you could always obtain a count
> looping over the rows in the result set

yep, with a .movefirst to go back to the start after the first time

But with both of these (.recordcount property and .movefirst method),
the availability of these will depend on (1) the ADO provider, and
(2) the cursor type.

Some ADO providers may support one or the other, or both, or none;
say, the FoxPro provider might not support them (it might, too, I don't
know; I'm speaking hypothetically).

In the case of .movefirst, you might get an error if it's not supported;
in the case of .recordcount, I think you get a result of -1.

The latter will also happen if the cursor type doesn't support this
operation: the default cursor, an adOpenForwardOnly, will return -1
because it can only move forward through the recordset for performance
reasons. You'd have to use Static or Keyset cursors, or a client-side
cursor (which in itself has some other advantages, but some nasty
disadvantages too). If you're using supporting cursors, though, then
you'll find that .recordcount it by far the easiest way.

If you do want to run a separate query, then you might want to consider
returning two result sets from the {query|proc}, and using .nextrecordset
to move between them, so
        count(*) AS LookitAllThemResults


one after the other. Schnazzy!

(note that if you DO use client-side recordsets, you CAN'T use
multiple record sets, which is a source of constant grief to me)

Hope this helps,


More information about the thelist mailing list