Solved

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

Posted on 2007-03-23
3
252 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
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…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

911 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