|
 |
aspx thread: Counting records Into a Standard variable.
Message #1 by "Salvador Gallego" <salvito@h...> on Tue, 27 Aug 2002 13:38:19
|
|
Hi,
I'm trying to make a Sql query on Page_Load wich count the records on my
DB, then I want to put the result on a variable to show it on the screen.
I'm using a "select count (*) into Variable..." but it just create a new
table on the DB called Variable, so it doesn't work.
How could I do that??
Thanks a lot in advance! .
From Spain:
Salvador Gallego.
Message #2 by "Juan T. Llibre" <j.llibre@c...> on Tue, 27 Aug 2002 08:35:55 -0400
|
|
Use "Select AS..." and not "Select INTO..."
Juan T. Llibre
Microsoft MVP [IIS/ASP]
ASP.NET en Espaņol : http://asp.net.do/
==============================
----- Original Message -----
From: "Salvador Gallego" <salvito@h...>
To: "ASP+" <aspx@p...>
Sent: Tuesday, August 27, 2002 1:38 PM
Subject: [aspx] Counting records Into a Standard variable.
> Hi,
>
> I'm trying to make a Sql query on Page_Load wich count the records on my
> DB, then I want to put the result on a variable to show it on the screen.
>
> I'm using a "select count (*) into Variable..." but it just create a new
> table on the DB called Variable, so it doesn't work.
>
> How could I do that??
>
> Thanks a lot in advance! .
>
> From Spain:
>
> Salvador Gallego.
> ---
>
> ASP.NET 1.0 Namespace Reference with C#
> http://www.wrox.com/acon11.asp?ISBN=1861007442
>
> ASP.NET 1.0 Namespace Reference with VB.NET
> http://www.wrox.com/acon11.asp?ISBN=1861007450
>
> These books are a complete reference to the ASP.NET namespaces
> for developers who are already familiar with using ASP.NET.
> There is no trivial introductory material or useless .NET
> hype and the presentation of the namespaces, in an easy-to use
> alphabetical order ensures a user-friendly reference format.
> We provide in-depth coverage of all the major ASP.NET classes,
> giving you those real-world tips that the documentation doesn't
> offer, and demonstrating complex techniques with simple
> examples.
>
> ---
Message #3 by "Sampath, Ramanujam (Cognizant)" <SRamanuj@c...> on Tue, 27 Aug 2002 18:27:16 +0530
|
|
well
On the Page_Load after successful connection and after implementing the
dataReader to the table in which u want to count the rows....
Dim Cnt as Integer
while DataReader.Read()
Cnt = Cnt + 1
End While
Now Cnt will give u the number of rows i the datareader which is the number
of records in the Table in DB..
keep me posted u still have issues....
==============================
S.Ramanujam
Programmer Analyst
Cognizant technology Solutions (p) Ltd. - CTS
38 & 39 Whites Road,
WCB - Whites Road Circular Building
Royapettah, Chennai - 600014
Ph : +xx xx xxx xxxx Extn 5113 [Off]
: +xx xx xxx xxxx [Res]
-----Original Message-----
From: Salvador Gallego [mailto:salvito@h...]
Sent: Tuesday, August 27, 2002 7:08 PM
To: ASP+
Subject: [aspx] Re: Counting records Into a Standard variable.
Hi,
I'm trying to make a Sql query on Page_Load wich count the records on my
DB, then I want to put the result on a variable to show it on the screen.
I'm using a "select count (*) into Variable..." but it just create a new
table on the DB called Variable, so it doesn't work.
How could I do that??
Thanks a lot in advance! .
From Spain:
Salvador Gallego.
---
ASP.NET 1.0 Namespace Reference with C#
http://www.wrox.com/acon11.asp?ISBN=1861007442
ASP.NET 1.0 Namespace Reference with VB.NET
http://www.wrox.com/acon11.asp?ISBN=1861007450
These books are a complete reference to the ASP.NET namespaces
for developers who are already familiar with using ASP.NET.
There is no trivial introductory material or useless .NET
hype and the presentation of the namespaces, in an easy-to use
alphabetical order ensures a user-friendly reference format.
We provide in-depth coverage of all the major ASP.NET classes,
giving you those real-world tips that the documentation doesn't
offer, and demonstrating complex techniques with simple
examples.
---
Message #4 by "Imar Spaanjaars" <Imar@S...> on Tue, 27 Aug 2002 14:27:51
|
|
IMO, this option causes way too much overhead. Suppose the datatable
contains 2.000.000 records. In your situation you would get them all over
to the client, loop through them without actually using them just to get a
recordcount. Seems pretty bad to me ;-)
Anyway, Salvador, you were half way there. Try this instead:
SELECT COUNT(*) FROM MyTable as NumOfRecords
Then use the ExecuteScalar method of the Oledb or SQLClient command
(depending on your connection type) to use the most effective way to get
the recordcount. ExecuteScalar returns the first column of the first
record only.
myCount = MyCommand.ExecuteScalar()
You may need to cast the result to be able to work with it.
For more info on the ExecuteScalar method, check this:
http://msdn.microsoft.com/library/default.asp?url=/library/en-
us/cpref/html/frlrfsystemdatasqlclientsqlcommandclassexecutescalartopic.asp
HtH
Imar
> well
On the Page_Load after successful connection and after implementing the
dataReader to the table in which u want to count the rows....
Dim Cnt as Integer
while DataReader.Read()
Cnt = Cnt + 1
End While
Now Cnt will give u the number of rows i the datareader which is the number
of records in the Table in DB..
keep me posted u still have issues....
==============================
S.Ramanujam
Programmer Analyst
Cognizant technology Solutions (p) Ltd. - CTS
38 & 39 Whites Road,
WCB - Whites Road Circular Building
Royapettah, Chennai - 600014
Ph : +xx xx xxx xxxx Extn 5113 [Off]
: +xx xx xxx xxxx [Res]
-----Original Message-----
From: Salvador Gallego [mailto:salvito@h...]
Sent: Tuesday, August 27, 2002 7:08 PM
To: ASP+
Subject: [aspx] Re: Counting records Into a Standard variable.
Hi,
I'm trying to make a Sql query on Page_Load wich count the records on my
DB, then I want to put the result on a variable to show it on the screen.
I'm using a "select count (*) into Variable..." but it just create a new
table on the DB called Variable, so it doesn't work.
How could I do that??
Thanks a lot in advance! .
From Spain:
Salvador Gallego.
|
|
 |