Link to home
Start Free TrialLog in
Avatar of inghfs
inghfsFlag for United Kingdom of Great Britain and Northern Ireland

asked on

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

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)
ASKER CERTIFIED SOLUTION
Avatar of ETA-TECHNICIANS
ETA-TECHNICIANS

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Member_2_3718378
Member_2_3718378

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 =-
Avatar of Anthony Perkins
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.