473,399 Members | 3,302 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,399 software developers and data experts.

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.CreateObject("ADODB.Connection")
objConn.Open "Driver={Microsoft Access Driver (*.mdb)};
DBQ=C:\Inetpub\wwwroot\spruce.mdb;"
strQuery = "SELECT * FROM schedule"
Set rst = Server.CreateObject("ADODB.recordset")
rst.Open strQuery, objConn
Set est = Server.CreateObject("ADODB.recordset")
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 10375
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*********@yahoo.com> wrote in message
news:Of**************@tk2msftngp13.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.CreateObject("ADODB.Connection")
objConn.Open "Driver={Microsoft Access Driver (*.mdb)};
DBQ=C:\Inetpub\wwwroot\spruce.mdb;"
strQuery = "SELECT * FROM schedule"
Set rst = Server.CreateObject("ADODB.recordset")
rst.Open strQuery, objConn
Set est = Server.CreateObject("ADODB.recordset")
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@typhoon01...
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:set objConn=nothing
if isArray(arResults) then
response.write Ubound(arResults,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******@NOyahoo.SPAMcom> wrote in message
news:O%****************@TK2MSFTNGP12.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:set objConn=nothing
if isArray(arResults) then
response.write Ubound(arResults,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******@NOyahoo.SPAMcom> wrote in message
news:O%****************@TK2MSFTNGP12.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:set objConn=nothing
if isArray(arResults) then
response.write Ubound(arResults,2) & " records" response.write Ubound(arResults,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
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...
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...
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...
1
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...
4
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...
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: 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...
1
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...
3
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...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.