Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: How to retrieve an Output Parameter using SQLDataSource Control

0 views
Skip to first unread message

REMOVE @removeopenmymindremovemetoo.andmenet Karl

unread,
Sep 6, 2004, 12:04:38 PM9/6/04
to
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 V...@discussions.microsoft.com> wrote in message
news:5A784C94-CA23-4CDA...@microsoft.com...
> 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

unread,
Sep 7, 2004, 10:02:16 AM9/7/04
to
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$oClEH...@tk2msftngp13.phx.gbl>...

REMOVE @removeopenmymindremovemetoo.andmenet Karl

unread,
Sep 7, 2004, 6:26:58 PM9/7/04
to
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" <jeff.v...@gmail.com> wrote in message
news:e9ee071.0409...@posting.google.com...

0 new messages