Reputation: 402
I've used the insert command through the code front in aspx and the output parameter is:
asp:Parameter Name="ReturnCustomerID" Type="String" Direction="Output"
and in the codebehind (C#) for OnInserted="SqlDS_CustomerDetails_OnInserted"
i have:
protected void SqlDS_CustomerDetails_OnInserted(object sender, SqlDataSourceStatusEventArgs e)
{
String newCustomerID;
newCustomerID = e.Command.Parameters["@ReturnCustomerID"].Value.ToString();
}
But for some reason I keep getting a null for my return value... I've tried executing the stored procedure direct in SQL server and it's fine and returns a proper ID but not in the c# or ASPX.
Is there a way to directly "eval" an output param to the text of a label in the code front? i.e.
asp:Label ID="NewCustomerID" runat="server" Text='<%# Eval("ReturnCustomerID") %>'>
I just need whichever method to bind the ID to that label.
Upvotes: 1
Views: 3197
Reputation: 59
I see you have set your ReturnCustomerID parameter type to String. When returning a string from a stored procedure as a return parameter, you must set the parameter to a non-null value before the stored proc is called - even if it's an output only parameter. So you'll need to make your parameter have a direction of InputOutput:
<asp:Parameter Name="ReturnCustomerID" Type="String" Direction="InputOutput">
and in the SqlDataSource.Inserting event you'll need to set a default:
e.Command.Parameters("@ReturnCustomerID").Value = "XXXXXXXXX"
See this link http://social.msdn.microsoft.com/Forums/en-SG/sqlintegrationservices/thread/6c95fa58-ad54-4626-96f5-339495c1715f
and scroll down to Paul Smith's post.
Upvotes: 1