Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: getting count(*) value


Message #1 by soni29@h... on Fri, 10 May 2002 04:21:24
hi,
is there any way to get the value held by count(*), suppose code is like:

Sub Page_Load()
 	Dim strConnection, strSQL, strSQL2 as String 
    Dim objConnection as Object
    Dim objCommand, objCommand2 as OledbCommand
    Dim objDataReader, objDataReader2 as OledbDataReader
    
    Dim total as Integer
    
    strSQL = "Select Count(*) as total from Student"
    strConnection 
= "provider=SQLOLEDB;server=localhost;database=Registrar;uid=sa;password=;"
	
	objConnection = New OledbConnection(strConnection)
	objCommand = New OledbCommand(strSQL, objConnection)
	objConnection.Open()
	objDataReader = objCommand.ExecuteReader()
	...

how would i get the number returned?
Message #2 by charles.lam@g... on Fri, 10 May 2002 11:29:18 +0800
You can use the following line to retrieve the count(*) value.

Dim myInteger as Integer
myInteger = objDataReader("total")

Cheers,
Charles Lam.





                                                                                                                                    
                      soni29@h...                                                                                             
                      m                        To:       "ASP+" <aspx@p...>                                           
                                               cc:                                                                                  
                      10/05/2002 12:21         Subject:  [aspx] getting count(*) value                                              
                      Please respond to                                                                                             
                      "ASP+"                                                                                                        
                                                                                                                                    
                                                                                                                                    




hi,
is there any way to get the value held by count(*), suppose code is like:

Sub Page_Load()
  Dim strConnection, strSQL, strSQL2 as String
    Dim objConnection as Object
    Dim objCommand, objCommand2 as OledbCommand
    Dim objDataReader, objDataReader2 as OledbDataReader

    Dim total as Integer

    strSQL = "Select Count(*) as total from Student"
    strConnection
= "provider=SQLOLEDB;server=localhost;database=Registrar;uid=sa;password=;"

 objConnection = New OledbConnection(strConnection)
 objCommand = New OledbCommand(strSQL, objConnection)
 objConnection.Open()
 objDataReader = objCommand.ExecuteReader()
 ...

how would i get the number returned?





This e-mail (and any attachment (s)) is confidential and for use only by
intended recipient (s). Access by others is unauthorised. Its content
should not be relied upon and no liability or responsibility is accepted by
us, without our subsequent written confirmation of its content. If you are
not an intended recipient, please notify us promptly and delete all copies
and note that any disclosure, copying, distribution or any action taken or
omitted to be taken in reliance on the information it contains is
prohibited and may be unlawful. Further information on Guoco Group is
available from http://www.guoco.com

Message #3 by "Robert Horn" <robertho@m...> on Fri, 10 May 2002 13:44:45 +1000
Try something like this:

Add the following lines:
objDataReader.Read()

Total = DBReader("Total")

Regards
Robert

----- Original Message -----
From: <soni29@h...>
To: "ASP+" <aspx@p...>
Sent: Friday, May 10, 2002 2:21 PM
Subject: [aspx] getting count(*) value


> hi,
> is there any way to get the value held by count(*), suppose code is like:
>
> Sub Page_Load()
>   Dim strConnection, strSQL, strSQL2 as String
>     Dim objConnection as Object
>     Dim objCommand, objCommand2 as OledbCommand
>     Dim objDataReader, objDataReader2 as OledbDataReader
>
>     Dim total as Integer
>
>     strSQL = "Select Count(*) as total from Student"
>     strConnection
> 
"provider=SQLOLEDB;server=localhost;database=Registrar;uid=sa;password=;"
>
> objConnection = New OledbConnection(strConnection)
> objCommand = New OledbCommand(strSQL, objConnection)
> objConnection.Open()
> objDataReader = objCommand.ExecuteReader()
> ...
>
> how would i get the number returned?

Message #4 by Feduke Cntr Charles R <FedukeCR@m...> on Fri, 10 May 2002 09:08:18 -0400
> is there any way to get the value held by count(*), suppose code is like:

	If you're only interested in retrieving the count and no other
values, then you should look into using

Int32 = OleDbCommand.ExecuteScalar();

which is much faster than the old method, and is designed specifically for
instances like this (and is therefore optimized).  ExecuteScalar returns the
first column of the first row of the recordset and nothing more.  If you
need a full code sample, let me know.

- Chuck

-----Original Message-----
From: soni29@h... [mailto:soni29@h...]
Sent: Friday, May 10, 2002 12:21 AM
To: ASP+
Subject: [aspx] getting count(*) value


hi,
is there any way to get the value held by count(*), suppose code is like:

Sub Page_Load()
 	Dim strConnection, strSQL, strSQL2 as String 
    Dim objConnection as Object
    Dim objCommand, objCommand2 as OledbCommand
    Dim objDataReader, objDataReader2 as OledbDataReader
    
    Dim total as Integer
    
    strSQL = "Select Count(*) as total from Student"
    strConnection 
= "provider=SQLOLEDB;server=localhost;database=Registrar;uid=sa;password=;"
	
	objConnection = New OledbConnection(strConnection)
	objCommand = New OledbCommand(strSQL, objConnection)
	objConnection.Open()
	objDataReader = objCommand.ExecuteReader()
	...

how would i get the number returned?

  Return to Index