Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 27th, 2006, 01:51 PM
Friend of Wrox
 
Join Date: May 2005
Posts: 189
Thanks: 0
Thanked 0 Times in 0 Posts
Default Select COUNT(*)

Hei!

Why does this not display the total number of records in the recordset?

set objRsTelle=server.createobject("ADODB.Recordset")

    objRsTelle.open "select COUNT(*) from Innsjekk", kobling, adOpenForwardOnly, adLockReadonly, adcmdtext

        if objRsTelle.eof then

            totaltRegistrert = objRsTelle

            else

        End if

            objRsTelle.Close

            set objRsTelle = Nothing

Response.write totaltRegistrert

With regards
grstad

__________________
Internet has become favorable with that tool...thank you Tim Berners-Lee!
 
Old April 28th, 2006, 03:16 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi grstad,

objRsTelle is a recordset, you need to get the value from a field within it.

Try this...
Code:
objRsTelle.open "select COUNT(*) AS recordcount from Innsjekk", kobling, adOpenForwardOnly, adLockReadonly, adcmdtext
totaltRegistrert = objRsTelle("recordcount").Value
HTH,

Chris

 
Old April 28th, 2006, 07:50 AM
Friend of Wrox
 
Join Date: May 2005
Posts: 189
Thanks: 0
Thanked 0 Times in 0 Posts
Default

...thank you for your reply Chris Scott! (I will sooon try it out) But I wonder; it seems to be so many varied versions of all of the sql-query methods. Is it one standard Vb-script SQL which fit the ASP-tech?

Vennlig hilsen
grstad

 
Old April 28th, 2006, 08:08 AM
Friend of Wrox
 
Join Date: May 2005
Posts: 189
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have changed the code somewhat, and it gives a 0x800A0E7D


dim objRsMenner,AlleMann,m

set objRsMenner=server.createobject("ADODB.Recordset")

(line 71) objRsMenner.open "SELECT COUNT(1) as m FROM Produkt WHERE ProduktKjonn = '" & mann & "' GROUP BY ProduktKjonn"'", kobling, adOpenStatic, adLockReadonly, adcmdtext

            AlleMann = objRsMenner("m").Value

            objRsMenner.Close

            set objRsMenner = Nothing




Feiltype:
ADODB.Recordset (0x800A0E7D)
Tilkoblingen kan ikke brukes til å utføre denne operasjonen. Den er enten lukket eller ugyldig i denne sammenhengen.
/innsjekk/treff_yngre.asp, linje 71

Med vennlig hilsen
grstad

 
Old April 28th, 2006, 08:26 AM
Friend of Wrox
 
Join Date: May 2005
Posts: 189
Thanks: 0
Thanked 0 Times in 0 Posts
Default

... it does work, the variable no holds "0"!. But it is records in the db with the value like "mann"!?

Med vennlig hilsen
grstad

 
Old April 28th, 2006, 11:01 AM
Friend of Wrox
 
Join Date: May 2005
Posts: 189
Thanks: 0
Thanked 0 Times in 0 Posts
Default

... it seems that an answer can be;

objRsMenner.open "SELECT COUNT(*) AS m, ProduktKjonn
FROM Produkt GROUP BY ProduktKjonn
ORDER BY COUNT(*) DESC;",
kobling, adOpenForwardOnly, adLockReadonly, adcmdtext

            AlleMann = objRsMenner("m").value

It is only two different values in the field ProduktKjonn. Either it is "mann" or it is "kvinne". The "DESC" in the query then sort out "menn", and count it to "some value". But what if there was more than two diff values in the field ProduktKjonn, and I want some value between "m" and "k"?. The WHERE...conditions, how does I get it to work?

Does anyone have the answer?

Med hilsen
grstad :)

...som har det med å svare seg selv!






Similar Threads
Thread Thread Starter Forum Replies Last Post
Select Count from multiple tables aspless SQL Language 1 January 30th, 2008 10:32 AM
How to get "SELECT COUNT(*)" return information? datagram ASP.NET 1.0 and 1.1 Basics 3 December 23rd, 2004 01:21 AM
SELECT COUNT as a ROW?? t0ny SQL Language 3 December 8th, 2004 05:31 AM
Select Where Greater Than Count [email protected] SQL Language 3 April 29th, 2004 05:14 AM
How to execute SELECT count(*) lxu Access 2 April 8th, 2004 08:16 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.