Solved

ASP and ADO: Why is recordset.PageCount returning -1?

Posted on 2007-03-23
3
248 Views
Last Modified: 2012-06-27
Why is recordset.PageCount returning -1? Given the ASP code below, the SQL returns serveral rows, however, when I try to use the result.RecordCount I always get -1. Why is this? And how can I get access to the size of the recordset 'result'?

Many Thanks

strSQL = "SELECT YEAR([Date]) As [Year], MONTH([Date]) As [Month], ROUND([Percent Return], 2), [Fund Name] FROM [Fund Perf] WHERE [Fund ID] = " & fundID & "ORDER BY [Date] asc"

      Set result = Server.CreateObject("ADODB.recordset")
      result.Open strSQL, connection
                             
      response.write(result.PageCount)
0
Comment
Question by:inghfs
3 Comments
 
LVL 4

Accepted Solution

by:
ETA-TECHNICIANS earned 500 total points
ID: 18781348
check your cursor

from: http://www.w3schools.com/ado/prop_rs_recordcount.asp

The RecordCount property returns a long value that indicates the number of records in a Recordset object.

If the Recordset object supports AbsolutePosition and AbsolutePage properties or bookmarks (if Supports(adApproxPosition) or Supports(adBookmark) returns true), this property will return the exact number of records in the Recordset.

Note: This property will return -1 for a forward-only cursor; the actual count for a static or keyset cursor; and -1 or the actual count for a dynamic cursor.

Note: The Recordset object must be open when calling this property. If this property is not supported it will return -1.
0
 
LVL 9

Expert Comment

by:deathtospam
ID: 18784183
inghfs --

ETA-TECHNICIANS is correct -- your cursor isn't set correctly, which is why RecordCount returns -1.  ASPFAQ.com does an excellent job of explaining this topic ( http://classicasp.aspfaq.com/general/why-does-recordcount-return-as-1.html ), but if all you want is an example, here it is:

=============================================
'// Set the recordset's CursorType property to "adOpenKeyset" (1).
'// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/mdmthrstopen.asp
Set result = Server.CreateObject("ADODB.recordset")
result.Open strSQL, connection, 1
iRecordCount = result.RecordCount
=============================================


-= DeathToSpam =-
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 18788855
Let's set the record straight:

First of all the reason you are getting a RecordCount of -1 is because the provider does not support the RecordCount property with the cursor you are using.  There is good reason for this:  The provider is making IMHO the very valid assumption that you want the fastest result possible.  If you do not care how long it takes or how much resources are occupied, consider using some other cursor type / location that does support this property.  If you do care about performance and resources used, than there are far better ways of doing it without using the RecordCount property.  If fact I will go out on a limb and suggest that you can do all you need with a performant cursor and never use the RecordCount property.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now