Re: How to retrieve an Output Parameter using SQLDataSource Control

Discussion in 'ASP .Net' started by Karl, Sep 6, 2004.

  1. Karl

    Karl Guest

    The only solution I've found to date is to hook to the Selected event of the
    SQlDataSource:

    <asp:sqldatasource ConnectionString="<%$ ConnectionStrings:portal %>"
    SelectCommand="GetPortals" ID="ds" runat="server">
    <SelectParameters>
    <asp:parameter Direction="Output" Type="Int32" Name="Output" />
    </SelectParameters>
    </asp:sqldatasource>


    and in codebehind

    void Page_Load(){
    ds.Selected +=new SqlDataSourceStatusEventHandler(ds_Selected);
    }
    void ds_Selected(object sender, SqlDataSourceStatusEventArgs e) {

    }

    at which point you can access e.Command.Parameters
    ["@Output"].SqlValue.Value or something similar.

    Karl

    --
    MY ASP.Net tutorials
    http://www.openmymind.net/
    "Jeff V" <Jeff > wrote in message
    news:...
    > Hello,
    >
    > I am trying to call a insert proc using the SQLDatasource Control. I was
    > able to call the insert just fine, but when I added an output param, I got
    > lost in how to retrieve that value. The proc is working fine, but does
    > anyone know how to get this value in .aspx (2.0)?
    >
    > Please let me know.
    >
    > Jeff V
    >
    Karl, Sep 6, 2004
    #1
    1. Advertising

  2. Karl

    Jeff V Guest

    Karl,

    Thanks for your reply. I'm not sure how this exactly works to get my
    return value from an insert statement using the selected event. Can
    you explain that further?

    Basically, I want to insert a row and then return the @@identity for
    that row. Which would then be used for another procedure. I know I
    can do it by using ADO.net. I'm trying to figure out the
    SQLDataSource in ASP.net 2.0

    Thanks,

    Jeff V

    "Karl" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in message news:<#Bph$>...
    > The only solution I've found to date is to hook to the Selected event of the
    > SQlDataSource:
    >
    > <asp:sqldatasource ConnectionString="<%$ ConnectionStrings:portal %>"
    > SelectCommand="GetPortals" ID="ds" runat="server">
    > <SelectParameters>
    > <asp:parameter Direction="Output" Type="Int32" Name="Output" />
    > </SelectParameters>
    > </asp:sqldatasource>
    >
    >
    > and in codebehind
    >
    > void Page_Load(){
    > ds.Selected +=new SqlDataSourceStatusEventHandler(ds_Selected);
    > }
    > void ds_Selected(object sender, SqlDataSourceStatusEventArgs e) {
    >
    > }
    >
    > at which point you can access e.Command.Parameters
    > ["@Output"].SqlValue.Value or something similar.
    >
    > Karl
    >
    > --
    > MY ASP.Net tutorials
    > http://www.openmymind.net/
    > "Jeff V" <Jeff > wrote in message
    > news:...
    > > Hello,
    > >
    > > I am trying to call a insert proc using the SQLDatasource Control. I was
    > > able to call the insert just fine, but when I added an output param, I got
    > > lost in how to retrieve that value. The proc is working fine, but does
    > > anyone know how to get this value in .aspx (2.0)?
    > >
    > > Please let me know.
    > >
    > > Jeff V
    > >
    Jeff V, Sep 7, 2004
    #2
    1. Advertising

  3. Karl

    Karl Guest

    Jeff,
    I didn't read your question properly (although I wasn't too far), here's how
    I got it working:

    <asp:SqlDataSource ConnectionString="<%$ ConnectionStrings:Test%>" ID="sql"
    Runat="server" SelectCommand="SELECT * FROM Organization"
    InsertCommand="AddOrganization">
    <insertparameters>
    <asp:parameter Name="Identity" Direction="ReturnValue" />
    </insertparameters>
    </asp:SqlDataSource>

    now the Sproc AddOrganization that I'm using to insert does a RETURN
    @@IDENTITY at the end....

    In my code file, I can then access this value via:

    private void Page_Load(object source, EventArgs e) {
    sql.Inserted += new SqlDataSourceStatusEventHandler(sql_Inserted);
    //hook up the Inserted event
    }

    void sql_Inserted(object sender, SqlDataSourceStatusEventArgs e) {
    int identity =
    Convert.ToInt32(((SqlParameter)e.Command.Parameters["@Identity"]).Value));
    }

    Karl


    --
    MY ASP.Net tutorials
    http://www.openmymind.net/


    "Jeff V" <> wrote in message
    news:...
    > Karl,
    >
    > Thanks for your reply. I'm not sure how this exactly works to get my
    > return value from an insert statement using the selected event. Can
    > you explain that further?
    >
    > Basically, I want to insert a row and then return the @@identity for
    > that row. Which would then be used for another procedure. I know I
    > can do it by using ADO.net. I'm trying to figure out the
    > SQLDataSource in ASP.net 2.0
    >
    > Thanks,
    >
    > Jeff V
    >
    > "Karl" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in

    message news:<#Bph$>...
    > > The only solution I've found to date is to hook to the Selected event of

    the
    > > SQlDataSource:
    > >
    > > <asp:sqldatasource ConnectionString="<%$ ConnectionStrings:portal %>"
    > > SelectCommand="GetPortals" ID="ds" runat="server">
    > > <SelectParameters>
    > > <asp:parameter Direction="Output" Type="Int32" Name="Output" />
    > > </SelectParameters>
    > > </asp:sqldatasource>
    > >
    > >
    > > and in codebehind
    > >
    > > void Page_Load(){
    > > ds.Selected +=new SqlDataSourceStatusEventHandler(ds_Selected);
    > > }
    > > void ds_Selected(object sender, SqlDataSourceStatusEventArgs e) {
    > >
    > > }
    > >
    > > at which point you can access e.Command.Parameters
    > > ["@Output"].SqlValue.Value or something similar.
    > >
    > > Karl
    > >
    > > --
    > > MY ASP.Net tutorials
    > > http://www.openmymind.net/
    > > "Jeff V" <Jeff > wrote in message
    > > news:...
    > > > Hello,
    > > >
    > > > I am trying to call a insert proc using the SQLDatasource Control. I

    was
    > > > able to call the insert just fine, but when I added an output param, I

    got
    > > > lost in how to retrieve that value. The proc is working fine, but

    does
    > > > anyone know how to get this value in .aspx (2.0)?
    > > >
    > > > Please let me know.
    > > >
    > > > Jeff V
    > > >
    Karl, Sep 7, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stu
    Replies:
    0
    Views:
    375
  2. Wayne Wengert

    Problem Using GUID as SQLDataSource Parameter

    Wayne Wengert, Feb 5, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    5,734
    Wayne Wengert
    Feb 6, 2006
  3. =?Utf-8?B?VmVhcg==?=
    Replies:
    1
    Views:
    5,019
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
    Mar 21, 2006
  4. VB.Net Pro
    Replies:
    2
    Views:
    796
    VB.Net Pro
    Oct 21, 2008
  5. Abraham Luna

    asp.net 2.0 SqlDataSource control parameter default value

    Abraham Luna, Aug 19, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    152
    Abraham Luna
    Aug 19, 2005
Loading...

Share This Page