1

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.

3
  • What happens if you leave out the "@" symbol? newCustomerID = e.Command.Parameters["ReturnCustomerID"].Value.ToString(); Commented Apr 3, 2013 at 20:13
  • same thing..but you would need the @ since it is an output parameter in the stored procedure Commented Apr 3, 2013 at 20:22
  • Shoot, I was hoping that ReturnValue thing was right. Well, I'm out of ideas for the moment. Good luck! Commented Apr 3, 2013 at 21:39

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.