Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Calling a Stored Procedure with Output Parameter
Message
From
28/06/2010 08:31:19
Timothy Bryan
Sharpline Consultants
Conroe, Texas, United States
 
 
To
25/06/2010 16:37:33
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Miscellaneous
Thread ID:
01470620
Message ID:
01470779
Views:
28
Frank,
Based on Bonnie's suggestion and solution I tried this original code again after changing the parameter direction to "InputOutput" and it also works fine.

Tim

>Hi,
>
>I am trying to follow the example in the help file to get a value out of a stored procedure.
>
>The stored procedure returns a string in its output parameter:
>
>
CREATE PROCEDURE TestNewNumber 
>
> @NewNumber varchar(10)
>OUTPUT
>AS
>BEGIN
>	-- SET NOCOUNT ON added to prevent extra result sets from
>	-- interfering with SELECT statements.
>	SET NOCOUNT ON;
>
>	SET @NewNumber = '00000'
>END
>
>
> RETURN @NewNumber
>
>The C# code I am using is this:
>
>
                // Create the parameter and set the direction
>                IDbDataParameter param1 = this.CreateParameter("@newNumber", 0);
>                param1.Direction = ParameterDirection.Output;
>
>                IDbCommand cmd;
>                this.ExecSprocScalar("TestNewNumber", out cmd, param1);
>
>                // Retrieve the value from the command object
>                IDbDataParameter param = (IDbDataParameter)cmd.Parameters["@newNumber"];
>                string newNumber = (string)param.Value;
>
>
>The problem is that param.Value is returning an integer (0 in this case) rather than the expected string '00000'.
>
>What am I doing wrong?
Timothy Bryan
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform