PDA

Click to See Complete Forum and Search --> : ADO reference returns -1 recordcount


sultan
Jul 27th, 2000, 10:41 AM
Hi
The following code displays the results howver the recordcount property of the ado recs recordset returns -1. There are over 100 records in the resultset!

Set Cons = New Connection
Set Recs = New Recordset

Cons.Open "provider=MSDASQL;dsn=accessextreme", "admin", ""
Recs.Open "select * from customer", Cons, adOpenDynamic, adLockOptimistic

Text1.DataField = "city"
Set Text1.DataSource = Recs



Can anyone please give help in this?

JHausmann
Jul 27th, 2000, 10:46 AM
You need to loop through the data.

add the following:

If Recs.EOF = False Then 'we got a count, this will tell us
Do While Not Recs.EOF
'do something with the data retrieved
Recs.MoveNext
Loop
End If

sultan
Jul 27th, 2000, 10:53 AM
Hi JH

Well I did try : recs.MoveLast and recs.MoveFirst

but even after this the recordcount value is the same = -1!

Latest: Also just now tried what you have suggested above no luck I am affraid.

[Edited by sultan on 07-27-2000 at 12:03 PM]

JHausmann
Jul 27th, 2000, 11:15 AM
Heh, OOps, I missed that one.

To get the record count, you could always issue

"select count(*) from customer"

sultan
Jul 28th, 2000, 05:56 AM
It didn't work, any more ideas?



This is really bewildering!

JHausmann
Jul 28th, 2000, 11:04 AM
It's not going to set "recordcount" but return a value that will represent what recordcount should have.

sultan
Jul 28th, 2000, 11:30 AM
Sorry What I meant was that I could not reset the recordset it complains that the recordset is already open. I know this is a silly question but, how do you feed a new select query to the already open recordset?

many thanks.

JHausmann
Jul 28th, 2000, 11:56 AM
I just open/close recordsets as many times as I need them.

ofert
Jul 29th, 2000, 11:01 AM
Here are 2 options out of some:
1) rs.open "SELECT COUNT(*) FROM mytable"
msgbox rs.fields(0) 'Your recordcount
2) On your original rs, using adOpenStatic Cursor will do the change.
Good Luke !

Clunietp
Jul 30th, 2000, 11:44 AM
Open the recordset using a client side static cursor. If this does not work, it is a deficiency in your ODBC driver.