Home > Archive > Microsoft SQL Server Desktop Engine > August 2005 > ADO recordcount returns -1









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author ADO recordcount returns -1
steve

2005-08-03, 3:23 am

Hi All

Upgraded Vb6 program from Access 2K to MSDE 2K RelA

Now all my checks for rs.recordcount return -1, except if I use Client side
cursor OR

if I use.... rs.Open sql, cn, adOpenKeyset, adLockReadOnly

Why is this?
I don't want to use client side cursors and I need to save data so
(adLockReadOnly) is no good

I have found that that checking for rs.eof seems reliable as a substitute
for recordcount but would like to understand the reasoning


Regards
Steve


Andrea Montanari

2005-08-03, 7:23 am

hi Steve,
steve wrote:
> Hi All
>
> Upgraded Vb6 program from Access 2K to MSDE 2K RelA
>
> Now all my checks for rs.recordcount return -1, except if I use
> Client side cursor OR
>
> if I use.... rs.Open sql, cn, adOpenKeyset, adLockReadOnly
>
> Why is this?
> I don't want to use client side cursors and I need to save data so
> (adLockReadOnly) is no good
>
> I have found that that checking for rs.eof seems reliable as a
> substitute for recordcount but would like to understand the reasoning


this is quiet normal using ADO recorset as the recordcount will be available
only when the entire rowset has been populated, ant this is true only when a
..movelast operation ins performed and all the data has been transferred..
please be warned that performing a rs.movelast + rs.movefirst can be a
timeconsuming operation for big results...
--
Andrea Montanari (Microsoft MVP - SQL Server)
http://www.asql.biz/DbaMgr.shtm http://italy.mvps.org
DbaMgr2k ver 0.14.0 - DbaMgr ver 0.59.0
(my vb6+sql-dmo little try to provide MS MSDE 1.0 and MSDE 2000 a visual
interface)
--------- remove DMO to reply


YYZ

2005-08-05, 11:23 am

> please be warned that performing a rs.movelast + rs.movefirst can be a
> timeconsuming operation for big results...


In addition to that, if you DO need to know how many rows you have
(which OP did not in this case), I would first run a select
count(afield) " and the same from/where clause that you use in the
other query. Actually, in those cases you can sometimes eliminate some
of the INNER JOINS that you might have to use when getting the full
field list, and some of the WHERE clause, too -- which will give you
your rowcount faster.

I do this a lot when I want to display a progress bar.

In addition, when looping through a recordset, I ALWAYS do until
rs.eof...I never use the .rowcount property for anything but advising
the user. Not sure WHY I do this, but I've been doing it for years...

Matt

Matt

Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com