Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Calling a Stored Procedure with Output Parameter
Message
From
25/06/2010 16:37:33
 
 
To
All
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Title:
Calling a Stored Procedure with Output Parameter
Miscellaneous
Thread ID:
01470620
Message ID:
01470620
Views:
97
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?
Frank.

Frank Cazabon
Samaan Systems Ltd.
www.samaansystems.com
Next
Reply
Map
View

Click here to load this message in the networking platform