Output parameters for OleDbParameter

  • Thread starter Thread starter Chris Simmons
  • Start date Start date
C

Chris Simmons

I am having a problem getting back the value of an output parameter
from a Sybase stored procedure. Would someone look at my code to see
what I'm doing wrong? I've attached a baseline test stored procedure
that takes one input parameter (and does nothing with it) and an
output parameter. Code follows..

Stored procedure:
-- BEGIN
CREATE PROCEDURE user.stored_procedure
(
@input int,
@output int OUTPUT
)
AS
BEGIN

SELECT @output = 3

RETURN 65

END
-- END

C# code snippet:

// ... BEGIN
OleDbConnection conn =
new OleDbConnection( "Provider=Sybase.ASEOLEDBProvider.2;Data
Source=DATASOURCE;User ID=USER;Password=PASSWORD;" );

OleDbCommand command = conn.CreateCommand();

command.CommandType = CommandType.StoredProcedure;
command.CommandText = "db.user.stored_procedure";

OleDbParameter inputParameter = null;
OleDbParameter outputParameter = null;

inputParameter = command.Parameters.Add( "@input", OleDbType.Integer
);
inputParameter.Value = 6;

outputParameter = command.Parameters.Add( "@output", OleDbType.Integer
);
outputParameter.Direction = ParameterDirection.Output;

try
{
conn.Open();

command.ExecuteNonQuery();

if ( outputParameter.Value is DBNull )
Console.WriteLine( "NULL" );
else
Console.WriteLine( outputParameter.Value.ToString() );

}
finally
{
conn.Dispose();
}
// ... END

The numbers in the SP are just random (65 and 3); no meaning. The
console output is always "NULL". I have read as much documentation as
I know of but cannot find the answer. Can anyone help?
 
Back
Top