Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RecordCount problem with ASP

Status
Not open for further replies.

CiaranReilly

Programmer
Feb 22, 2006
2
GB
Hi Guys,

Sorry if this seems like a stupid question, but I was wondering if anyone could shed some light on an issue I'm having with the ADO RecordCount function in an ASP script. Basically, it's the classic problem where the RecordCount always reads -1.

I've done a bit of reading, and discovered that you need to use the .Open method on the recordset object, instead of .Execute, which I have done. I'm also specifying adOpenStatic as the cursortype, to no avail.

I don't know if I'm just being stupid, but I really can't see what's causing the problem, as everything has been done according to the reccomendations.
I have posted my code below in the hope that someone can shed some light on it !
The database is SQL Server 2000, and the ASP script is running on IIS6 on Windows Server 2003, not that that should matter.
Any help much appreciated !

Code:
strCon = "Provider=SQLOLEDB;Server=risk-assessment;User ID=sa;Password=******";Database=Clients;"

'Setup our database...
Set adoCon = Server.CreateObject("ADODB.Connection")
'Set the connection string to the database:
adoCon.connectionstring = strCon
'Set an active connection to the Connection object:
adoCon.Open
'Setup RecordSet object
Set rsCommon = Server.CreateObject("ADODB.Recordset")

'Prepare query to grab data
strQuery = "SELECT * FROM ClientDetails"

rsCommon.Open strQuery, adoCon, adOpenStatic

'Lets see if we can count some records:
intRecordCount = rsCommon.RecordCount
Response.Write("Record Count: " & intRecordCount) 

'Tidy up:
rsCommon.Close
Set rsCommon = Nothing
 
Try setting the cursor location to client-side.

Also make sure that the constant adOpenStatic is defined.
 
Thanks for your help guys, setting the cursor location to 3 solved it.
Sorry for posting something that was already in the FAQ, it didn't come up in search results earlier for some reason.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top