Stupid question - binding an <asp:label> --> stored procedure returning a scalar?

H

Homer J. Simpson

I have the following stored procedure:

ALTER PROCEDURE [dbo].[spGetQuickNoteCount]
AS
BEGIN
SET NOCOUNT ON;
SELECT COUNT(*) FROM QUICKNOTES
END

....and the following data source in my .aspx file:

<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$
ConnectionStrings:csToolbar %>"
SelectCommand="spGetQuickNoteCount" SelectCommandType="StoredProcedure">
</asp:SqlDataSource>

Now...how do I go about binding an <asp:label> so it simply displays the
scalar returned by the stored procedure? I've used gridviews and repeaters
in the past, but those were always bound to a data source that returned
recordsets, not just a scalar.

I suppose I could write code in Page_Load() to connect to the database, run
the stored procedure and set the label's .Text property to the value
returned, but that's just adding extra code I'd like to avoid.

I'm sure I've missed something obvious here...
 
S

Sherif Elmetainy

You simply put the label in a repeater, since ExecuteScaler simply returns
the first field in the first record of the result rowset.
 
H

Homer J. Simpson

You simply put the label in a repeater, since ExecuteScaler simply returns
the first field in the first record of the result rowset.

That's what I thought...but what do you use for the binding expression? I
tried the following:

<asp:Repeater ID="rptNoteCount" runat="server"
DataSourceID="SqlDataSource2">
<ItemTemplate>
<asp:Label ID="lblNotes" runat="server"><%#Eval( ??? ) %></asp:Label>
</ItemTemplate>
</asp:Repeater>

....what are you supposed to use for "???", since the field is unnamed?
 
H

Homer J. Simpson

...what are you supposed to use for "???", since the field is unnamed?

Never mind. I've named the field by modifying the stored procedure as:

SELECT COUNT(*) AS NUMBER FROM QUICKNOTES

....and then using Eval( "NUMBER" )


I could swear I had tried it already but it still came back blank. I'm as
much of a noob at SQL as I am at ASP.NET. :eek:)

Thanks "Sherif".
 

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,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top