Question

ASP Recordset count

Asked by: trashy

How 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.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
1999-07-01 at 08:45:08ID10177671
Tags

asp

,

recordset

Topic

Web Authoring

Participating Experts
5
Points
400
Comments
18

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

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.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

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.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

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.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. RecordCount!!!
    hie... i've been running through my database in my ASP page...and i've run recordcount function...but it use to return -1 for me although my database got 3 records. how? below is my sourceocdes:- sqlStr = "SELECT * FROM [movie] WHERE " + _ "[show...
  2. RecordSet in ASP
    Hello all, Iam looping through a recordset in ASP to create a table However when in a current record in the loop is there a way I can get a field value from the next record without moving to the next record in the recordset? Note: Iam not using the GetRows method. Iam loopi...
  3. Recordset and RecordCount
    HI everyone! I am having some trouble reading the recordcount value from a recordset. It always appears to be -1. Any suggestions? Here i write som code: Session("constr")= "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" & ...
  4. db.execute Vs db.openrecordset
    G'day. Trying to insert form data via VBA. Prior, I've always done the following to insert data. dim db as database set db = currentDb sqlString = "insert into table("blah")values("blah1","blah2") etc. db.execute sqlString ...
  5. Multiple Recordset
    I have a asp page that is building a interface to a DB. I can read one recordset but i wish to us the page to get multiple recordsets to buid drop down lists for the user to select from. My problem is that the page stalls and does not build every time i am using a second reco...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

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.

Join the Community

Answers

 

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.

 

by: mayhewPosted on 1999-07-01 at 09:12:56ID: 1863695

Try doing a movelast and then a movefirst so that the recordset value gets populated.

 

by: trashyPosted on 1999-07-01 at 09:13:20ID: 1863696

Just got hold of a database crack.
he recommended the following:

<%recordset.movelast%>
<% = RecordSet.RecordCount%>
<%recordset.movefirst%>

I'll try it when I'm home tonight.

 

by: trashyPosted on 1999-07-01 at 09:15:38ID: 1863697

Sorry, mayhew. Didn't see your comment before.

But thanks anyway

cheers   trashy

 

by: mgfranzPosted on 1999-07-01 at 09:16:25ID: 1863698

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.OLEDB.3.51;" & _                   "Data Source=d:\vb5_win95\nwind.mdb", _                    adOpenDynamic, adLockUnspecified        
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.


 

by: mgfranzPosted on 1999-07-01 at 09:22:32ID: 1863699

Or this: (the MoveLast is the key...)

Sub Form_Load ()      
Dim MyDB As Database, MyDyna As Dynaset
Set MyDB = OpenDatabase("C:\VB3\BIBLIO.MDB")
Set MyDyna = MyDB.CreateDynaset("Authors")      MyDyna.MoveLast
MyRecordCount = MyDyna.RecordCount      
MyDyna.Close      

form1.Show
Print MyRecordCount  
End Sub

 

by: mayhewPosted on 1999-07-02 at 20:21:03ID: 1863700

So did you get this working?

 

by: vendrigPosted on 1999-07-05 at 05:43:01ID: 1863701

You have to do movelast as mayhew suggested, because the engine doesn't know how many records it retrieved until it has walked through them.

 

by: trashyPosted on 1999-07-05 at 08:09:37ID: 1863702

As soon as I add the 'recordset.movelast' I get the following error:

The rowset does not support fetching backwards

I also tried to set the CursorType but didn't suceed.
Can any one help me with VBScript syntax to set the cursor type?

 

by: mayhewPosted on 1999-07-05 at 10:34:55ID: 1863703

We need to see the code you're using.

Can you post it?

 

by: trashyPosted on 1999-07-06 at 14:15:10ID: 1863704

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.Connection")
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(MySQL)
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

 

by: mgfranzPosted on 1999-07-06 at 15:28:30ID: 1863705

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("Authors") ' Open dB field Authors
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").CreateDynaset("Field1")
rs.MoveLast
rsRecordCount = rs.RecordCount
rs.Close

Mark

 

by: trashyPosted on 1999-07-08 at 14:01:27ID: 1863706

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

 

by: mayhewPosted on 1999-07-08 at 14:16:43ID: 1863707

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.

 

by: trashyPosted on 1999-07-09 at 00:31:37ID: 1863708

I tried this already. I actually work with a local variable for my DB. I just left it out, because I didn't think it makes any difference. I assume you'll get the following message when you try it:

The rowset does not support fetching backwards.

 

by: yerffoegPosted on 1999-07-13 at 05:11:42ID: 1863709

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.

 

by: yerffoegPosted on 1999-07-13 at 05:17:28ID: 1863710

Here's an article referring to what I was saying:

http://www.4guysfromrolla.com/webtech/120898-1.shtml

 

by: trashyPosted on 1999-07-16 at 15:16:39ID: 1863711

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

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...