Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Re: How to retrieve an Output Parameter using SQLDataSource Control

Reply
Thread Tools

Re: How to retrieve an Output Parameter using SQLDataSource Control

 
 
Karl
Guest
Posts: n/a
 
      09-06-2004
The only solution I've found to date is to hook to the Selected event of the
SQlDataSource:

<asp:sqldatasource ConnectionString="<%$ ConnectionStringsortal %>"
SelectCommand="GetPortals" ID="ds" runat="server">
<SelectParameters>
<asparameter 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 http://www.velocityreviews.com/forums/(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
 
 
 
Jeff V
Guest
Posts: n/a
 
      09-07-2004
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$(E-Mail Removed)>...
> The only solution I've found to date is to hook to the Selected event of the
> SQlDataSource:
>
> <asp:sqldatasource ConnectionString="<%$ ConnectionStringsortal %>"
> SelectCommand="GetPortals" ID="ds" runat="server">
> <SelectParameters>
> <asparameter 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 (E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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
> >

 
Reply With Quote
 
 
 
 
Karl
Guest
Posts: n/a
 
      09-07-2004
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>
<asparameter 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.Parameter s["@Identity"]).Value));
}

Karl


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


"Jeff V" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed). ..
> 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$(E-Mail Removed)>...
> > The only solution I've found to date is to hook to the Selected event of

the
> > SQlDataSource:
> >
> > <asp:sqldatasource ConnectionString="<%$ ConnectionStringsortal %>"
> > SelectCommand="GetPortals" ID="ds" runat="server">
> > <SelectParameters>
> > <asparameter 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 (E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > > 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
> > >



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SQLDataSource parameter referencing a text box in a user control? VB.Net Pro ASP .Net 2 10-21-2008 04:06 PM
Retrieve SQL Data via VB Code (not sqldatasource control) =?Utf-8?B?VmVhcg==?= ASP .Net 1 03-21-2006 04:08 AM
Problem Using GUID as SQLDataSource Parameter Wayne Wengert ASP .Net 3 02-06-2006 04:20 PM
using SqlDataSource with parameter that is filled in other control Stu ASP .Net 0 10-07-2005 07:00 PM
asp.net 2.0 SqlDataSource control parameter default value Abraham Luna ASP .Net Datagrid Control 0 08-19-2005 01:34 PM



Advertisments