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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Number of Records in a Recordset

Status
Not open for further replies.

sandylou

Programmer
Jan 18, 2002
147
US
This is probably an easy one for you out there, but I want to know the number of records in my recordset. I tried rs.Recordcount but that gives me a -1. How can I get the number of records?
 
How not to return -1 for a record count.

strConn is the DSNLess connection

Set conn=Server.CreateObject("ADODB.Connection")
conn.Open strConn

Set RS = Server.CreateObject("ADODB.Recordset")
RS.CursorLocation = adUseClient

strSQL = "Select * from dbname ;"

RS.Open strSQL, Conn, adOpenStatic, adLockReadOnly, adCmdText

response.write rs.recordcount




Chris.

Indifference will be the downfall of mankind, but who cares?
 
I have what you listed except this is my connection string:

strConnection = "Driver={SQL Server};Server=(local);Database=myDB;Uid=muID;Pwd=myPWD"

I get the following error:

Error Type:
ADODB.Recordset (0x800A0BB9)
Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.
 
hi,
recordset returns -1 in case of the forwardonly case try for another cursor type
bhoge
 
I think the order of your objects may be wrong. Try this:

strConnection = "Driver={SQL Server};Server=(local);Uid=muID;Pwd=myPWD;Database=myDB"

TwoOdd
--------------
Good judgment comes from experience, and experience comes from bad judgment.
-- Barry LePatner
 
Here is what I have and it still produces -1 for the recordcount:
<%
strConnection = &quot;Driver={SQL Server};Server=(local);Uid=myUID;Pwd=myPwd;Database=myDB&quot;

Set objConn = Server.CreateObject(&quot;ADODB.Connection&quot;)
objConn.Open strConnection

Set objRS = Server.CreateObject(&quot;ADODB.Recordset&quot;)


strProc = &quot;Select * from tblTest&quot;


objRS.CursorLocation = adUseClient

objRS.Open StrProc,objConn,adOpenForwardOnly,adLockReadOnly, adCmdText

%>

I have also switch the CursorType and it doesn't see to work. Thanks for your help so far!! :)
 
Assuming the error message relates to the objRS.Open.

Is the adovbs constants file in place and included.

try replacing the constants with the values,

objRS.CursorLocation = 3

objRS.Open strProc,objConn,3,1,&H0001

response.write the strProc and objConn to make sure they are valid



Chris.

Indifference will be the downfall of mankind, but who cares?
 
Thanks! That Worked! I appreciate your time!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top