RS.RecordCount always returns -1

J

jl

Hello,
I am trying to determine if a recordset is empty or not, and if
it is empty print out a message saying no records found. I thought
I could use rs.RecordCount but it always seems to return -1 no
matter if there are records in the rs or not. Does anyone have
any ideas as to why this doesn't work and how to get it to work.
Thanks in advance. The code is below.
Joe

Const adOpenStatic = 3
Const adLockReadOnly = 1
Dim frmFileType, frmCategory, frmEvent, frmUser, objConn2, objRS5
Dim tmpsql5, strSQL5
frmFileType = request.form("fileType")
frmCategory = request.form("category")
frmEvent = request.form("theevent")
frmUser = request.form("theUser")
if frmUser = "ALL" then
userPart = ""
Else
userPart = "And user_id = " & frmUser
End if
tmpsql5 = "Select * from table where type_id = " & frmFileType & " AND
category_id = " & frmCategory & " AND event_id = " & frmEvent &
userPart
strSQL5 = tmpsql5
Set objConn2=Server.CreateObject("ADODB.Connection")
Set objRS5=Server.CreateObject("ADODB.Recordset")
objConn2.Open strConnect
objRS5.Open strSQL5, objConn2, adOpenStatic, adLockReadOnly
i=objRS5.RecordCount
response.write("The number of records is: " & i)
 
C

Curt_C [MVP]

jl said:
Hello,
I am trying to determine if a recordset is empty or not, and if
it is empty print out a message saying no records found. I thought
I could use rs.RecordCount but it always seems to return -1 no
matter if there are records in the rs or not. Does anyone have
any ideas as to why this doesn't work and how to get it to work.
Thanks in advance. The code is below.
Joe


Perhaps...
http://www.aspfaq.com/show.asp?id=2193
 
A

Aaron Bertrand [SQL Server MVP]

I am trying to determine if a recordset is empty or not, and if
it is empty print out a message saying no records found. I thought
I could use rs.RecordCount

Why not use the EOF property?

set rs = conn.execute(sql)
if rs.eof then
Response.Write "no results"
else
...
end if
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,527
Members
44,997
Latest member
mileyka

Latest Threads

Top