Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 RecordCount return -1

Author  Topic 

fan
Starting Member

10 Posts

Posted - 2004-06-16 : 02:09:05
Hi all,

I am using VBA+ADO for a small project. when I use Recordset to get data back from SQL Server 2000, the RecordCount attribute only gives me -1.

I use this:
sqlstr = "select * from mytable"
myrecordset.Open sqlstr, conn, adOpenStatic, adLockOptimistic

The problem is this recordset does contain 60 records and I can read them out, and the Cursor type is adOpenStatic, Recordcount should return the actural number of recordset,rite?

Any one can help?

Many Thanks

timmy
Master Smack Fu Yak Hacker

1242 Posts

Posted - 2004-06-16 : 02:23:43
You'd think so, wouldn't you?

DAO did things like this, but ADO doesn't

The RecordCount property returns the number of records you've read so-far. So, as you step through the recordset, the count grows. For small recordsets like you're dealing with, I would:

rst.Open
rst.MoveLast
counter = rst.RecordCount
rst.MoveFirst

A pain in the butt, but it works....

Tim
Go to Top of Page

fan
Starting Member

10 Posts

Posted - 2004-06-16 : 02:24:35
if I change Lock type to adLockReadOnly, it will give me the right answer, Why?

Any comments?
Go to Top of Page

timmy
Master Smack Fu Yak Hacker

1242 Posts

Posted - 2004-06-16 : 02:36:07
Probably because the whole cursor is loaded at once into the recordset object, rather than loaded on demand with the other rst types
Go to Top of Page

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2004-06-16 : 07:23:53
What you also could do is this:

myArray = myrecordset.GetRows
ArraySize = Ubound(myArray, 2)
Go to Top of Page
   

- Advertisement -