NEWBIE: RecordCount of SqlDataSource

D

Daan

Hi!

I have this SqlSataSource (aspx 2.0):

<asp:SqlDataSource ID="ArtiestenSource" Runat="server"
SelectCommand="SELECT lower(artiest) AS artiest, COUNT(DISTINCT album) AS
albums, COUNT(artiest) AS tracks, SUM(seconden) AS seconden,
CONVERT(varchar, DATEADD(second, SUM(seconden), ''), 108) AS Duur FROM
dbo.muziek GROUP BY artiest"
ConnectionString="Server=DESERVER;User
ID=sa;Password=wachtwoord;Database=Muziek;Persist Security Info=True"
ProviderName="System.Data.SqlClient">
</asp:SqlDataSource>

Maybe someone knows how to retrieve the number of rows of this datasource?
(ArtiestenSource.RecordCount doesn't work. )

Also: I would display this number of rows like this:
<% response.write(ArtiestenSource.RecordCount) %>

But I don't doubt there is a typical dot net 2.0 way of displaying this
result. (So, something else then <% response.write() %>.
If I am right about that, does someone know what right way is?

Thanks!

Daan
 
C

Cowboy \(Gregory A. Beamer\) [MVP]

You should be able to extract the DataSet and pull the number out (would
give you code, but I do not have the 2.0 machine up and running). As far as
how to embed the number in a page, you have two choices.

1. Add a label and set the Text property
2. Use data binding <%# =variableName %> - just set the variableName in the
back and make sure it is accessible. You will have to run Page.DataBind() to
ensure it is bound, however.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

************************************************
Think Outside the Box!
************************************************
 
D

Daan

Hi!
Does anyone know how to extract the DataSet from a SqlDataSource?
(I have really been searching and trying, but I can't figger it out -> a
real newbie?)

Thanks!

Daan
 
G

Guest

Daan:

Here is another way to get the record count: The SqlDataSource has an event
called "Selected." It passes in a SqlDataSourceStatusEventArgs, which has a
property called "AffectedRows." I just tried hooking this event after calling
a simple select to the Products table of Northwinds and got the rowcount.

Chuck
 
Joined
Mar 18, 2009
Messages
5
Reaction score
0
Can't you simply do a COUNT of your selected data like this?

Code:
SELECT COUNT(*) AS RecordCount
FROM (SELECT lower(artiest) AS artiest, COUNT(DISTINCT album) AS
albums, COUNT(artiest) AS tracks, SUM(seconden) AS seconden,
CONVERT(varchar, DATEADD(second, SUM(seconden), ''), 10 AS Duur FROM
dbo.muziek GROUP BY artiest)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,135
Latest member
VeronaShap
Top