Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Keeps Returning a Value of 0
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Keeps Returning a Value of 0

 Post Reply Post Reply Page  12>
Author
ldiuf View Drop Down
Groupie
Groupie


Joined: 17 October 2001
Location: United States
Status: Offline
Points: 49
Post Options Post Options   Thanks (0) Thanks(0)   Quote ldiuf Quote  Post ReplyReply Direct Link To This Post Topic: Keeps Returning a Value of 0
    Posted: 23 September 2003 at 12:34pm

Can someone please look at this? This just keeps giving me a count of     0    when I know that there are at least 10 that should be showing.


'--- establish access connection
Sub OpenDB (ByRef con, d)
 DSN ="ConversionDB_DSN"
 Set con = Server.CreateObject("ADODB.Connection")
 con.Open DSN
End Sub
'--- end establish access connection

OpenDB con, "Admin"
Set type = "Yes"
    icount = 0
SQL = "SELECT * FROM tblConversions Where fldConverted='" & type & "'"
Set rs = con.Execute(SQL)
  i = rs.RecordCount
     Do While icount < i And not rs.EOF
    icount = icount+1
   rs.MoveNext
 Loop
Response.write "" & icount & "" & vbcrlf

Thanks In Advance,

Larry

Back to Top
FLATLINE View Drop Down
Groupie
Groupie
Avatar

Joined: 08 July 2002
Location: Israel
Status: Offline
Points: 142
Post Options Post Options   Thanks (0) Thanks(0)   Quote FLATLINE Quote  Post ReplyReply Direct Link To This Post Posted: 23 September 2003 at 1:01pm

I'm not sure but I think you need to set a special LockType for the recordset if you're gonna use RecordCount.

Either way, it's not really needed anyway. You can (and should) do it without the i counting, like this:

Set rs= con.Execute(SQL)
 While NOT rs.EOF
    icount = icount+1
    rs.MoveNext
 WEND
Response.Write "" & icount & "" vbcrlf

Visit my site: DarkGreen HQ
Back to Top
michael View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 April 2002
Location: United States
Status: Offline
Points: 4670
Post Options Post Options   Thanks (0) Thanks(0)   Quote michael Quote  Post ReplyReply Direct Link To This Post Posted: 23 September 2003 at 1:57pm

If all you do is counting why don't you just do a
Select Count(*) as noofrecords FROM tblConversions Where fldConverted='" & type & "'"

This just retrurns one value, the amount of records to your criteria, much faster the looping through the whole junk.

Back to Top
FLATLINE View Drop Down
Groupie
Groupie
Avatar

Joined: 08 July 2002
Location: Israel
Status: Offline
Points: 142
Post Options Post Options   Thanks (0) Thanks(0)   Quote FLATLINE Quote  Post ReplyReply Direct Link To This Post Posted: 23 September 2003 at 2:30pm

Michael, I'm glad you've mentioned that SQL statement because I'm a bit confused about how it works... How exactly will I be able to use the counted number later on? Is the statement simply creating a variable named noofrecords and puts the count value in it? Or do I have to access the variable through the recordset, like rs("noofrecords") ?

Hehe, sorry for stealing the topic, Idiuf

Visit my site: DarkGreen HQ
Back to Top
michael View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 April 2002
Location: United States
Status: Offline
Points: 4670
Post Options Post Options   Thanks (0) Thanks(0)   Quote michael Quote  Post ReplyReply Direct Link To This Post Posted: 23 September 2003 at 2:55pm
rs("noofrecords") As count only returns one record you can skip the looping and such. And yes, it just returns one integer value
Back to Top
Flamewave View Drop Down
Senior Member
Senior Member
Avatar

Joined: 19 June 2002
Location: United States
Status: Offline
Points: 376
Post Options Post Options   Thanks (0) Thanks(0)   Quote Flamewave Quote  Post ReplyReply Direct Link To This Post Posted: 24 September 2003 at 7:14am

Just an FYI, if you need to return the record count along with a bunch of records, you can do it like this:

SELECT (SELECT Count(*) FROM table WHERE column1 = 1) AS NumRecords, column1, column2 FROM table WHERE column1 = 1 ORDER BY column2 ASC

this will return a recordset like this:

NumRecords   column1   column2
3           ;        1           ;   0
3           ;          1           ;   6
3           ;        1           ;   8

- Flamewave

They say the grass is greener on the other side, but if you really think about it, the grass is greener on both sides.
Back to Top
ldiuf View Drop Down
Groupie
Groupie


Joined: 17 October 2001
Location: United States
Status: Offline
Points: 49
Post Options Post Options   Thanks (0) Thanks(0)   Quote ldiuf Quote  Post ReplyReply Direct Link To This Post Posted: 24 September 2003 at 8:43am
Thank GOD that this forum exists!!!
Back to Top
3BEPb View Drop Down
Groupie
Groupie


Joined: 07 August 2003
Location: United States
Status: Offline
Points: 81
Post Options Post Options   Thanks (0) Thanks(0)   Quote 3BEPb Quote  Post ReplyReply Direct Link To This Post Posted: 26 September 2003 at 12:20am

Originally posted by FLATLINE FLATLINE wrote:

I'm not sure but I think you need to set a special LockType for the recordset if you're gonna use RecordCount.
Problem with Count(*) has been resolved, as I see, but FYI I usually use following locks, when I want recordset to do whatever I want ():

RS.Open "SELECT bla_bla_regular_select_statement",,adOpenStatic,adLockReadOn ly



Edited by 3BEPb
Back to Top
 Post Reply Post Reply Page  12>

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.