tags:

views:

206

answers:

2

Just starting to learn ASP.NET (C#) and I am using Visual Studio 2008.

I have a stored procedure:

ALTER PROCEDURE dbo.StoredProcedure1    
AS
SET NOCOUNT ON 
SELECT MAX(issue_id) FROM tableb as max_issue_id
RETURN

Which is linked to a sqlDataSource.

How do I retrieve the value from the stored procedure by using the sqlDataSource? Ideally I would like to assign this value to a variable/textbox/label.

+1  A: 

How about something like

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
        ConnectionString="<%$ ConnectionStrings:myConnectionString %>"
        ProviderName="System.Data.SqlClient" 
        SelectCommand="StoredProcedure1" 
        SelectCommandType="StoredProcedure">
        <SelectParameters>
         <asp:ControlParameter ControlID="txtOut" Name="cpOut"     PropertyName="Text" Type="Int32" />
        </SelectParameters>
    </asp:SqlDataSource>
Tim Hoolihan
Gotta love data access code in the user interface </sarcasm>
Lars A. Brekken
A: 

Thanks Tim.

My final result was:

    <form id="form1" runat="server">
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
        SelectCommand="zorro" SelectCommandType="StoredProcedure"></asp:SqlDataSource>
    <br />
    <asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1">
        <ItemTemplate>
            zorro:
            <asp:Label ID="zorroLabel" runat="server" Text='<%# Eval("zorro") %>' />
            <br />
            <br />
        </ItemTemplate>
     </asp:DataList>
     </form>
John M