473,626 Members | 3,246 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

RecordCount

I know for a fact that in my database, I have three records under the users
table. However when I execute this code:

--------------BEGIN CODE----------------

Set objConn = Server.CreateOb ject("ADODB.Con nection")
objConn.Open "Driver={Micros oft Access Driver (*.mdb)};
DBQ=C:\Inetpub\ wwwroot\spruce. mdb;"
strQuery = "SELECT * FROM schedule"
Set rst = Server.CreateOb ject("ADODB.rec ordset")
rst.Open strQuery, objConn
Set est = Server.CreateOb ject("ADODB.rec ordset")
est.Open "SELECT * FROM users", objConn
est.MoveFirst
Response.Write est.RecordCount

----------------------END CODE ------------------------------

It prints out "-1" instead of "3"

Any idea why this may be happening? Am I using RecordCount correctly? All
I wanna do is know the number of records resulting from my query without
using a silly loop.
Jul 19 '05 #1
6 10395
Default cursor type is 'firehose' forward-only server-side which doesn't
populate the recordcount property.

Try doing:

..MoveLast
..MoveFirst

to populate the recordcount or consider a client-side cursor (all data gets
transferred to the client).

Chris.

"Mark Watkins" <ma*********@ya hoo.com> wrote in message
news:Of******** ******@tk2msftn gp13.phx.gbl...
I know for a fact that in my database, I have three records under the users
table. However when I execute this code:

--------------BEGIN CODE----------------

Set objConn = Server.CreateOb ject("ADODB.Con nection")
objConn.Open "Driver={Micros oft Access Driver (*.mdb)};
DBQ=C:\Inetpub\ wwwroot\spruce. mdb;"
strQuery = "SELECT * FROM schedule"
Set rst = Server.CreateOb ject("ADODB.rec ordset")
rst.Open strQuery, objConn
Set est = Server.CreateOb ject("ADODB.rec ordset")
est.Open "SELECT * FROM users", objConn
est.MoveFirst
Response.Write est.RecordCount

----------------------END CODE ------------------------------

It prints out "-1" instead of "3"

Any idea why this may be happening? Am I using RecordCount correctly? All
I wanna do is know the number of records resulting from my query without
using a silly loop.

Jul 19 '05 #2
rs.Open strSQL, objConn, adLockReadOnly, adCmdTable
dblrecordCount = rs.RecordCount

-dlbjr

Discerning resolutions for the alms
Jul 19 '05 #3
Not meaning to offend but Mark isn't really going to be able to learn
anything from such a short reply that makes no attempt to explain why the
issue is occurring?
Brings to mind the adage about 'Give a man a meal and he'll eat for a day
but give him the knowledge and tools to grow his own and he'll never want
for food again'?

Chris.

"dlbjr" <do******@do. u> wrote in message
news:epjob.159$ Qy4.13102@typho on01...
rs.Open strSQL, objConn, adLockReadOnly, adCmdTable
dblrecordCount = rs.RecordCount

-dlbjr

Discerning resolutions for the alms

Jul 19 '05 #4
Chris Barber wrote:
Default cursor type is 'firehose' forward-only server-side which
doesn't populate the recordcount property.

Try doing:

.MoveLast
.MoveFirst
to populate the recordcount
There are some problems with this advice:
1. Since it's a forward-only cursor, the MoveFirst method will usually not
be supported. Some providers, however, will support it, but their method of
supporting it may not be to your liking: MoveFirst causes the recordset to
be requeried, which can have a large impact on performance. If the provider
does not support MoveFirst with forward-only cursors, and error will be
raised.
2. Even if the MoveFirst is supported, it will still be a forward-only
cursor, and RecordCount will still contain -1 after the MoverFirst. This is
different from the behavior of DAO recordsets.

or consider a client-side cursor (all
data gets transferred to the client).

That will definitely work. However, you do not need a client-side cursor to
get a recordcount: there are several server-side cursor types that will
support record-count: static, keyset, dynamic, and with the Jet provider,
Table.

However, I do not recommend opening one of the non-default cursor types
merely to get a record count. The non-default cursor types require more
resources and do not perform as well as the default due to the extra
functionality offered. There are other ways to get a record count from a
default forward-only cursor. My favorite is to use GetRows to stuff the data
from the recordset into an array. This has two benefits:
1. I can immediately close the recordset and connection, allowing other
threads on the server to use the connection instead of creating a new one.
2. I can work with the data in the array, which will be much quicker than
using a cursor to work with it.

Once the data is in the array, you can use Ubound to determine the number of
records:

est.Open ...
if not est.EOF then arResults = est.GetRows
est.close: set est = nothing
objConn.close:s et objConn=nothing
if isArray(arResul ts) then
response.write Ubound(arResult s,2) & " records"
else
response.write "no records"
end if

HTH,
Bob Barrows

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 19 '05 #5
"Bob Barrows" <re******@NOyah oo.SPAMcom> wrote in message
news:O%******** ********@TK2MSF TNGP12.phx.gbl. ..
Once the data is in the array, you can use Ubound to determine the number of records:

est.Open ...
if not est.EOF then arResults = est.GetRows
est.close: set est = nothing
objConn.close:s et objConn=nothing
if isArray(arResul ts) then
response.write Ubound(arResult s,2) & " records"
else
response.write "no records"
end if


Plus 1.

Haven't we had this conversation already. :)

http://groups.google.com/groups?selm...TNGP12.phx.gbl
Jul 19 '05 #6
Chris Hohmann wrote:
"Bob Barrows" <re******@NOyah oo.SPAMcom> wrote in message
news:O%******** ********@TK2MSF TNGP12.phx.gbl. ..
Once the data is in the array, you can use Ubound to determine the

number of
records:

est.Open ...
if not est.EOF then arResults = est.GetRows
est.close: set est = nothing
objConn.close:s et objConn=nothing
if isArray(arResul ts) then
response.write Ubound(arResult s,2) & " records" response.write Ubound(arResult s,2) + 1 & " records"
else
response.write "no records"
end if


Plus 1.

Haven't we had this conversation already. :)

http://groups.google.com/groups?selm...TNGP12.phx.gbl

Wow! This is an example of a mistake I would never make in my own code but
which keeps slipping into my air code examples! Thanks for the re-catch!

Bob

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 19 '05 #7

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

Similar topics

2
5067
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
12
2966
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 SELECT_WITH_PAGING 'CustomerID, ShipName', 'OrderID', 'Northwind.dbo.Orders', 3, 10, 1, '', 'OrderDate'...
2
2072
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 records. what did i do? how can i avoid this to happen again? please help! nick_faye
1
2401
by: JMCN | last post by:
hello- i have created a tabular form using records from a specific query. then users will filter out the specific data. the next step is to take the count of the current records (daily open items), then use the total number of daily open items to calculate the percentage to all open items for the month. my first question is how would i be able to capture the current filtered openrecordset and count the records? would i use the
4
4880
by: don.fleming | last post by:
Hi folks: Am doing a VBA SQL Select stmt with multiple rows found and not getting RecordCount > 1. I've verified there are multiple rows found by copying my SQL stmt from Debug window and pasting it to a query - retrieves many rows. I need to program to handle many Rows in VBA. Suggestions much appreciated! Here is an excerpt of my VBA code after the SQLstmt is built: Debug.Print SQLstmt Set RecSet1 = SQLtbl.OpenRecordset(SQLstmt)
10
6718
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 established by the user to narrow the scope but I don't want to display the form if there are no...
2
2160
by: rajvbprogramer | last post by:
here is my problem. i have two records. one containing 20 records and second containing 30 records. now i want the recordcount property to use and go to the 21 record. i m calculating the recordcount of both the record. now i m doing this a = rs.recordcount b = rs1.recordcount for x = b+1 to a
1
2475
by: qqmbers | last post by:
May be it will help someone. I faced the strange problem with RecordCount property of cloned Recordset within the Current event handler. The RecordCount value was correct every time I had diagnostic message boxes turned on or when I debugged the handler step by step. And these values became incorrect in normal mode (to be exact they became wrong after the first occurrence of "no records" case). I tried to use MoveFirst and MoveLast...
3
11063
by: sparks | last post by:
Is recordcount a little messed or what? For Each tdf In dbs.TableDefs If Left(tdf.Name, 3) = "tbl" Then Debug.Print tdf.Name Debug.Print tdf.RecordCount it prints the correct name but the RecordCount is off on 8 out of 30 tables. the only thing is all the correct ones don't have any records LOL
0
8711
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, 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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8642
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8368
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8512
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7203
agi2029
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5576
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4094
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4206
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2630
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.