CRecordset::GetRecordCount() -> Question! 
Author Message
 CRecordset::GetRecordCount() -> Question!

Hi,

CRecordset::GetRecordCount()

When I read MFC reference we have to call MoveNext repeatedly until IsEOF
returns nonzero.

Anybody knows how to use without calling MoveNext()?

Thanks.

Roger.



Sat, 03 Aug 2002 03:00:00 GMT  
 CRecordset::GetRecordCount() -> Question!
My bad.  I was thinking of DAO which both says:

<MSDN>
Use the RecordCount property to find out how many records in a Recordset or
TableDef object have been accessed. The RecordCount property doesn't
indicate how many records are contained in a dynaset-, snapshot-, or
forward-only-type Recordset object until all records have been accessed.
Once the last record has been accessed, the RecordCount property indicates
the total number of undeleted records in the Recordset or TableDef object.
To force the last record to be accessed, use the MoveLast method on the
Recordset object. You can also use an SQL Count function to determine the
approximate number of records your query will return.
</MSDN>

BTW, for ADO it says:

<MSDN>
Use the RecordCount property to find out how many records are in a Recordset
object. The property returns -1 when ADO cannot determine the number of
records or if the provider or cursor type does not support RecordCount.
Reading the RecordCount property on a closed Recordset causes an error.

If the Recordset object supports approximate positioning or bookmarks-that
is, Supports (adApproxPosition) or Supports (adBookmark), respectively,
return True-this value will be the exact number of records in the Recordset
regardless of whether it has been fully populated. If the Recordset object
does not support approximate positioning, this property may be a significant
drain on resources because all records will have to be retrieved and counted
to return an accurate RecordCount value.

The cursor type of the Recordset object affects whether the number of
records can be determined. The RecordCount property will return -1 for a
forward-only cursor, the actual count for a static or keyset cursor, and
either -1 or the actual count, depending on the data source, for a dynamic
cursor.
</MSDN>

So apparently you don't need to use either MoveLast or MoveNext Until EOF
with ADO.

-Paul

--------------------------------------------------------
Paul Little, Senior Programmer/Analyst
SVi Retail Systems
San Diego, CA


Quote:


> > Can't you just call CRecordset::MoveLast() instead of repeatedly calling
> > MoveNext()??
> <snip>

> No, that *may* work with some ODBC drivers,
> but it definitely doesn't work with any I've tested.
> Microsoft don't even suggest that it might work.

> from the MSDN on GetRecordCount,

> <MSDN>
> Caution   The record count is maintained as a "high water mark" - the
> highest-numbered record yet seen as the user moves through the records.
The
> total number of records is only known after the user has moved beyond the
> last record. For performance reasons, the count is not updated when you
call
> MoveLast. To count the records yourself, call MoveNext repeatedly until
> IsEOF returns nonzero. Adding a record via CRecordset:AddNew and Update
> increases the count; deleting a record via CRecordset::Delete decreases
the
> count.
> </MSDN>



Sat, 03 Aug 2002 03:00:00 GMT  
 CRecordset::GetRecordCount() -> Question!
Roger, you'd probably get more/better responses if
you post this sort of question in the sibling newsgroup,

microsoft.public.vc.database

AFAIK you can't circumvent the need to step through
the recordset if you want to use the GetRecordCount()
function.

Usually I code a select count(*) from <blah> where <blah>
and submit that first then take the result if I want to know
how many records will be returned in a given recordset.

HTH

-------------------------------------------------------------------
"If you think you know the answer,
then you don't understand the question !"
-------------------------------------------------------------------


Quote:
> Hi,

> CRecordset::GetRecordCount()

> When I read MFC reference we have to call MoveNext repeatedly until IsEOF
> returns nonzero.

> Anybody knows how to use without calling MoveNext()?

> Thanks.

> Roger.



Sun, 04 Aug 2002 03:00:00 GMT  
 CRecordset::GetRecordCount() -> Question!

Quote:
> My bad.  I was thinking of DAO which both says:

<snip>

I figures that Jet (DAO) can return a meaningful value in the
same way that the BDE can for dBase and Paradox.

<snip>

Quote:

> BTW, for ADO it says:

<snip>

True, but it does indicate also that you either incur a performance
hit or non-support for ADO (probably once again related to the
underlying ODBC drivers). I'm yet to get a portable solution without
resorting to using the SQL COUNT(*) option. From what I read it
didn't necessarily return the "not deleted", "not empty" records which
is what I'm (funnily enough) more interested in.... :-)

<snip>

Quote:

> So apparently you don't need to use either MoveLast or MoveNext Until EOF
> with ADO.

> -Paul

<snip>

Dunno....

<re-quote MSDN>
...this property may be a significant drain on resources because all records
will have to be retrieved and counted to return an accurate RecordCount
value.
</re-quote MSDN>

It *would* be nice, but from the tests I've done and seen elsewhere
to date, the result always seems to be that it internally steps (quickly)
through the recordset to calculate the answer if it supports it at all...

Have you tried it Paul ?



Sun, 04 Aug 2002 03:00:00 GMT  
 CRecordset::GetRecordCount() -> Question!
Zorallin,

I have occasionally used MoveLast & RecordCount with both DAO and ADO, but
mostly I use SELECT COUNT(*) FROM ... due to the performance implications
you so eloquently emphasized in your post.

-Paul

--------------------------------------------------------
Paul Little, Senior Programmer/Analyst
SVi Retail Systems
San Diego, CA


Quote:

<snip>

> It *would* be nice, but from the tests I've done and seen elsewhere
> to date, the result always seems to be that it internally steps (quickly)
> through the recordset to calculate the answer if it supports it at all...

> Have you tried it Paul ?



Sun, 04 Aug 2002 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. newbie question >>>

2. sizeof() question >>> :)

3. SDK DAO and GetRecordCount

4. CRecordset::GetFieldValue returns <space>

5. CRecordset->Delete() Problem

6. How to do a CRecordset->FindFirst

7. CRecordSet -> no data

8. CRecordset->Update(), But no Update

9. CDaoRecordSet::GetRecordCount()

10. (ADO) Why GetRecordCount() Never Works??

11. CRecordSet->AddNew() Problem

12. getrecordcount

 

 
Powered by phpBB® Forum Software