Try doing a movelast and then a movefirst so that the recordset value gets populated.
Main Topics
Browse All TopicsHow can I get the number of recordsets retreaved by the SQL Query?
<% SQL_Query = "SELECT * FROM Table1 WHERE Field1 >= 0"%>
<% set RecordSet = db.Execute(SQL_Query)%>
<% = RecordSet.RecordCount%><br
ASP seems to know the .RecordCount but always returns -1, whatever numer of Recordsets I got.
Thanks Trashy
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Cursor type...
When you request the RecordCount for a serverside recordset, a -1 may return. This occurs with ActiveX Data Objects (ADO) version 2.0 when the CursorType is adOpenForwardonly or adOpenDynamic. This occurs with ADO 1.5 only when the cursortype is adOpenForwardonly.
When you select a CursorType that is not supported, the provider should select the CursorType closest to what you request. Also, please note that not all combinations of LockType and CursorType work together. Changing a LockType may force a change in the CursorType. Be sure to use debug to check the value of CursorType when conducting tests with your OLEDB provider.
Use either adOpenKeyset or adOpenStatic as the CursorType for server side cursors or use a client side cursor. Client side cursors use only adOpenStatic for CursorTypes regardless of which CursorType you select.
Dim rs As ADODB.Recordset
Private Sub Form_Load()
'set up rs
Set rs = New ADODB.Recordset
rs.CursorLocation = adUseServer
rs.Open "Select ProductID from products", & "Provider=Microsoft.Jet.OL
Debug.Print rs.RecordCount
End Sub
Replace the preceding Data Source with a Data Source on your computer. Run the preceding form and note the record count. Change the CursorType to adOpenForwardonly and note the record count.
Change the CursorLocation to adUseClient and experiment with the different CursorTypes. In all cases the correct record count returns.
mgfranz
Sorry, can't get it to work.
I never wrote VB only VBScript, but there seems to be a difference in connecting databases.
The code I'm using:
IN THE GLOBAL.ASA FILE:
**************************
Set Session("db") = Server.CreateObject("ADODB
Session("db").Open "MyDB"
**************************
executing global.asa is no problem, it works.
IN THE TEST.ASP FILE:
**************************
MySQL = "SELECT * FROM Table1 WHERE Field1 = 11"
set rs = Session("db").Execute(MySQ
rs.MoveLast
**************************
As soon as I use movelast I get the error message.
'80040e24', 'The rowset does not support fetching backwards'
I tried to get your example to work, but didn't succeed.
trashy
Why are you doing this?
MySQL = "SELECT * FROM Table1 WHERE Field1 = 11"
You are querying field1 where data = 11... Don't you want to count the # of enteries in field1?
Read these lines carefully:
Set MyDyna = MyDB.CreateDynaset("Author
MyDyna.MoveLast ' Move to last record
MyRecordCount = MyDyna.RecordCount ' Count the records
MyDyna.Close ' Close the dB
Print MyRecordCount ' Print the results
So, in your file, try this: (untested...)
set rs = Session("db").CreateDynase
rs.MoveLast
rsRecordCount = rs.RecordCount
rs.Close
Mark
Ok, ok, it shouldn't be Field1 = 11 it rather should be Field1 > 11.
Anyway, it doesn't work. I get the following message:
The application is using arguments that are of the wrong type, are out of acceptable range, or are in conflict with one another.
Sorry, but at the moment I'm short in time for my web project. I don't have time to work on it all the time, so I think I will close this question thread unless someone has a solution that he knows it will work.
For the meantime I go for siabods solution. that one works.
Thanks for your help
Trashy
Something just occurred to me. I know you don't have time to work on it, but I wanted to throw it out there. I'll check it later myself.
I've never tried to directly manipulate a db object that is stored in a session variable.
I've always defined a local variable in the asp page and set it equal to the session db object. That is:
IN THE TEST.ASP FILE:
**************************
MySQL = "SELECT * FROM Table1 WHERE Field1 > 11"
set LocalDB = Session("db")
set rs = LocalDB.Execute(MySQL)
rs.MoveLast
**************************
Again, I'll try this myself later and let you know what I come up with.
You need to include the file adovbs.inc to be able to use
the adOpenStatic, etc, keywords as these are just number representations for the CursorType, etc.
You should NEVER use movelast, movefirst to get the RecordCount, and should definitely not loop through the entire recordset to find out how many records there are. This is very resource intensive.
Either open the correct recordset type unless you can't in which case the easiest way to do it if you can only open Firehose cursors (forwardonly), is to use COUNT in SQL. This is the easily the fastest way to count records.
i.e. SELECT COUNT(*) FROM table WHERE Field11 = 11
If you need the recordset information as well you will have to create another recordset. This will always be faster if you cannot get the RecordCount, and it is often faster to do it this esp. with large recordsets way unless you need to be able to page back through a recordset.
Here's an article referring to what I was saying:
http://www.4guysfromrolla.
It would have been nice if you would have had included the AS in the query (like below). I mean, somehow I have to get the number of records. :-)
SELECT COUNT(*) AS numOfRecs FROM table WHERE Field1 > = 1
But anyway, I'm happy with your answer, especially with your added comment with the link to the 4 guys.
That was it. Thanks to everyone.
Trashy
Business Accounts
Answer for Membership
by: siabodPosted on 1999-07-01 at 08:50:33ID: 1863694
Yeah have been having the same problems too, in the end i just gave up....here's my work around :
<%MyCounter=0%>
<%Do while not recordset.eof%>
<%recordset.movenext%>
<%MyCounter=MyCounter+1%>
<%Loop%>
<%recordset.movefirst%>
Then the var MyCounter is the number of records and your pointer is back to the first record of the recordset
Hope you'll find the right answer though...but this works anyhow.