Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Calling a Stored Procedure with Output Parameter
Message
 
 
To
25/06/2010 17:46:09
Timothy Bryan
Sharpline Consultants
Conroe, Texas, United States
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Miscellaneous
Thread ID:
01470620
Message ID:
01470639
Views:
32
Good point. I also don't see where we set the type of the parameter and its length.

>Hi Frank,
>If you are creating a parameter that is a VarChar(10) why are you initializing it with a 0 (zero) when you create it with CreateParameter? Shouldn't you be initialziing it with a string value?
>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?
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform