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("f ileType")
frmCategory = request.form("c ategory")
frmEvent = request.form("t heevent")
frmUser = request.form("t heUser")
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.Connectio n")
Set objRS5=Server.C reateObject("AD ODB.Recordset")
objConn2.Open strConnect
objRS5.Open strSQL5, objConn2, adOpenStatic, adLockReadOnly
i=objRS5.Record Count
response.write( "The number of records is: " & i) 4 15127
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
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.
> 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(sq l)
if rs.eof then
Response.Write "no results"
else
...
end if
Hello,
EOF is what I ended up using.
Thanks for all of your suggestions.
Joe This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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. Here's the code
(I have left out the details for the connection string):
-------------------
strSQL = "SELECT * from orders"
strConnect =
Set...
|
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 number of records returned though?
Please help,
Jeff
P.S.
I am using VBScript for my code connecting to a SQL Server 2000 database
|
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?
|
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 getting the Recordset? In QA,
the RecordCount displays below the Recordset.
The below USAGE code will display my SPROC results.
USAGE:
EXEC...
|
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 = oWS.OpenDatabase("mydb", , True)
Set oRs = oDB.OpenRecordset(sSQL)
Debug.Print oRs.RecordCount
It only returns 1 record.
| |
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 records. but as i
manipulate the table, (add, delete, etc) i get errors and when i
checked my recordcount, it returns 1 more than the actual # of...
|
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 cannot get it to
work today. I've studied both my old and new code and cannot see a
reason why it's doing what it is. I've been hammering my head...
|
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 contains only tables. I have linked the tables for the
front end to the back end database.
I am trying to set the recordsource of a form to a query...
|
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 msgbox and capture the query its running and when i run it in a query it returns the all the records.
The interface is in access but it is linked to...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |