Re: How to retrieve an Output Parameter using SQLDataSource Control

K

Karl

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
 
J

Jeff V

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 said:
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 said:
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
 
K

Karl

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 said:
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: said:
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 said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top