473,785 Members | 2,794 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

I have the following stored procedure:

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

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

<asp:SqlDataSou rce ID="SqlDataSour ce2" runat="server" ConnectionStrin g="<%$
ConnectionStrin gs:csToolbar %>"
SelectCommand=" spGetQuickNoteC ount" SelectCommandTy pe="StoredProce dure">
</asp:SqlDataSour ce>

Now...how do I go about binding an <asp:labelso 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...
Aug 27 '07 #1
3 2574
You simply put the label in a repeater, since ExecuteScaler simply returns
the first field in the first record of the result rowset.

"Homer J. Simpson" <ro**@127.0.0.1 wrote in message
news:ue******** *****@TK2MSFTNG P06.phx.gbl...
>I have the following stored procedure:

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

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

<asp:SqlDataSou rce ID="SqlDataSour ce2" runat="server"
ConnectionStrin g="<%$ ConnectionStrin gs:csToolbar %>"
SelectCommand=" spGetQuickNoteC ount"
SelectCommandTy pe="StoredProce dure">
</asp:SqlDataSour ce>

Now...how do I go about binding an <asp:labelso 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...

Aug 27 '07 #2
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="rptNoteCoun t" runat="server"
DataSourceID="S qlDataSource2">
<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?
Aug 27 '07 #3
...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. :o)

Thanks "Sherif".
Aug 27 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
28068
by: June Moore | last post by:
Hi all, I have a stored procedure that return a resultset e.g. stored proc: get_employee_details select emp_id, emp_name, emp_salary, emp_position from empoloyee I would like to write another stored procedure that executes the above stored procedure - returning the same number of records but it will only show 2 columns
5
22657
by: Member | last post by:
Hi All. Maybe someone in here could help on this too.... Uusally I can return a value from a stored procedure without any problem. Today I ran into something I cannot figure out. Basically....what I am doing is a couple of inserts or updates depending on what is being passed.
1
5548
by: Robin Tucker | last post by:
Hi, I have one stored procedure that calls another ( EXEC proc_abcd ). I would like to return a result set (a temporary table I have created in the procedure proc_abcd) to the calling procedure for further manipulation. How can I do this given that TABLE variables cannot be passed into, or returned from, a stored procedure? Thanks,
2
1086
by: ACase | last post by:
Hello; I am having an interesting problem. I have an application which allows a user to enter data on the front end (Broswer HTML/ASP), click on a button and using the entered data runs some calculations and returns the data. Everything works fine, all the fields all the calulcations up to a certain amount of entered characters. Not sure why.
3
5820
by: Suresh | last post by:
Hi All I am writing Import\Export routine in DB2 using stored procedure and front end as JAVA. For this I have two option 1) Writing five different stored procedure returning one cursor (recordset each) 2) Writing one stored procedure returning five different cursor (five
5
2961
by: Laurie Murphy | last post by:
I have been researching this problem for a week now and I haven't found anything that works. Here is the problem: We recently removed the SET ANSI_WARNINGS OFF code at the top of all of our triggers because they were causing way too many recompiles and we were seeing locking, blocking and timeouts. Unfortunately, we are now seeing many application errors (VB6) where the warnings are causing errors in our recordsets and return values. The...
0
2083
by: adougall | last post by:
I would like to know what the outcome was on the topic for Nested Stored Procedure returning result sets in DB2 on AS/400 was. I am getting the same problem RESULT_SET_LOCATOR in *LIBL type *SQLUDT not found.
0
1277
by: sck10 | last post by:
Hello, How do you turn on paging on a GridView? I am binding a stored procedure in my code file using the following: OracleDataReader sdrSearch = cmdSearch.ExecuteReader(); this.gvSearchList.DataSource = sdrSearch; this.gvSearchList.DataBind(); On my GridView, I have AllowPaging="True". However, when I set
6
25162
by: Constantine AI | last post by:
Can anyone help? Ive created the below stored procedure to allow an input parameter of post code to be entered to display properties which have this post code. The procedure creates fine but because i have two properties with the post code 'S1 4SG', the execution of the procedure fails, it gives the error: ERROR at line 1: ORA-01422: exact fetch returns more than requested number of rows ORA-06512: at "CBRAID.PROC_PROPSEARCH", line 19...
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10329
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10152
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10092
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8974
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7500
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3650
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.