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.
| 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, adLockOptimisticThe 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'tThe 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.Openrst.MoveLastcounter = rst.RecordCountrst.MoveFirstA pain in the butt, but it works....Tim |
 |
|
|
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? |
 |
|
|
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 |
 |
|
|
Lumbago
Norsk Yak Master
3271 Posts |
Posted - 2004-06-16 : 07:23:53
|
| What you also could do is this:myArray = myrecordset.GetRowsArraySize = Ubound(myArray, 2) |
 |
|
|
|
|
|
|
|