ADODB.RecordSet, RecordCount always return -1

S

Serge Myrand

Hi,

I have an ADODB.RecordSet that RecordCount alway return -1 and this
RecordSet is plenty of record!

R.RecordSet = -1
R.eof = False
R.BOF = False

Is the cursor is lost somewhere?

How can I do to get the number of record in the result set?

Thank you in advance
serge
 
I

IPT

I went to the web, and still unable to get it work.

My codes:

sSQL = "SELECT * FROM myTable"
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open sSQL, myConn, 1, 3
recCount = rs.recordcount
rs.Close
Set rs = Nothing
response.write recCount

It returns -1.

Help!
 
B

Bob Barrows [MVP]

Are you Serge?

What is your backend database?
I went to the web, and still unable to get it work.

Why bother? If you read the article I linked to, you will find a more
efficient method (using GetRows) for getting the record count than using an
expensive cursor for your recordset.
My codes:

sSQL = "SELECT * FROM myTable"
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open sSQL, myConn, 1, 3

You do not need an ultra-expensive keyset cursor (although it should work).
All you need is a static cursor. The locktype does not matter.
rs.Open sSQL, myConn, 3, 3, 1
recCount = rs.recordcount
rs.Close
Set rs = Nothing
response.write recCount

Does this reflect your actual purpose? You are opening a recordset for the
sole purpose of getting the record count? That's crazy! Don't pull all the
records from your table across the wire simply to count them.

sSQL = "SELECT count(*) FROM myTable"
set rs = conn.execute(sSQL,,1)
recCount = rs(0)
rs.Close
Set rs = Nothing
conn.Close
Set conn= Nothing
response.write recCount
It returns -1.

Help!

It should not return -1 with a keyset cursor, unless the provider you are
using for your connection does not support bookmarks. That is why I asked
what database you are using, and why I am now asking you to show us your
connection string (with any password information censored of course).

Bob Barrows
 
I

IPT

I'm not Serge.

I use mySQL 4.0, does it support bookmark (.AbsolutePage)?

I used to use Ms Access, and has many functions. Since migrate to mySQL, I
need to modify many codes pertaning to SQL systax. I can't use anymore saved
queries, nested select, etc. Even the 'getdate()' has changed to 'Now()'.

Any free database server you may suggest?
 
B

Bob Barrows [MVP]

IPT said:
I'm not Serge.

I use mySQL 4.0, does it support bookmark (.AbsolutePage)?

I have no idea. One way to find out is to use the Supports method.
http://msdn.microsoft.com/library/en-us/ado270/htm/mdmthsupports.asp

http://msdn.microsoft.com/library/en-us/ado270/htm/mdprorecordcount.asp

I used to use Ms Access, and has many functions. Since migrate to
mySQL, I need to modify many codes pertaning to SQL systax. I can't
use anymore saved queries, nested select, etc. Even the 'getdate()'
has changed to 'Now()'.

Any free database server you may suggest?

Why not MSDE?

Bob Barrows
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top