473,407 Members | 2,314 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

RS.RecordCount always returns -1

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)

Aug 4 '05 #1
4 15112
jl wrote:
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

--
Curt Christianson
site: http://www.darkfalz.com
blog: http://blog.darkfalz.com
Aug 4 '05 #2
Curt_C [MVP] wrote:
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...


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


While this article addresses the RecordCount problem, it seems like an
over-engineered solution to the simple problem of determining if there are
any results present.

Given the question and the code sample provided by the OP, shouldn't it
suffice for him to examine objRS5.EOF?

--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
Aug 4 '05 #3
> 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
Aug 5 '05 #4
jl
Hello,
EOF is what I ended up using.
Thanks for all of your suggestions.
Joe

Aug 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Navin Kulshreshtha | last post by:
Hi folks, I'm opening a recordset with a SQL statement and then trying to use the .RecordCount property to count the number of rows in the recordset. For some reason, it is always returning -1....
2
by: Jeff Boyer | last post by:
Hello everyone, Can someone tell me why a ADO recordset.recordcount would return a -1? I have confirmed that it has records in it by writing some values to the screen. Why can't I count the...
7
by: Serge Myrand | last post by:
Hi, I have an ADODB.RecordSet that RecordCount alway return -1 and this RecordSet is plenty of record! R.RecordSet = -1 R.eof = False R.BOF = False Is the cursor is lost somewhere?
12
by: scott | last post by:
In LISTING 2, I have a SPROC that returns a recordset and a recordcount in SQL QA. I can access the Recordset with no problem. How can I grab the Recordcount with ASP code at the same time I'm...
5
by: michael montagne | last post by:
Problem with this statement: sSQL = "SELECT * FROM Projects;" Set oDbe = CreateObject("DAO.DBEngine.36") oDbe.SystemDB = "myworkgrupfile.MDW" Set oWS = oDbe.CreateWorkspace("", "me", "") Set oDB...
2
by: nick_faye | last post by:
why does my recordcount returns the # of actual records + 1? btw, i am using ms access. i don't know what happened but at first, my table seems ok. the recordcount returns the correct # of...
2
by: Andy_Khosravi | last post by:
This is probably one of the most simple things to do in VB, yet somehow I've messed it up and cannot get it to work properly. I've used it dozens of times in the past, but for whatever reason I...
10
by: Robert | last post by:
How do you get an accurate count of the number of records returned from a query when using linked tables. I have an access 2003 database as a front end to another access 2003 database that...
2
by: smook | last post by:
I have some code in an ONCURRENT event that is running a query and then counting the number of records returned. However the RecordCount is always returning 1. I know the query works .. i put a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.