?
Solved

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

Posted on 2007-03-23
3
Medium Priority
?
277 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 4

Accepted Solution

by:
ETA-TECHNICIANS earned 2000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

762 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