Parameter.Value proper cast with c# oracle number to c# int??
10626Jul 9 2004 — edited Jul 9 2004Hello,
I'm trying to get a return value from an Oracle stored function using C# and odp.net.
The function basically looks like:
function f( id in number ) return number
is
id_new number := null;
begin
select sequenct_name.nextval
into id_new
from dual;
-- do some stuff
return id_new;
end;
The C# call basically looks like
cmd.Parameters.Clear();
cmd.CommandText = "f";
cmd.CommandType = CommandType.StoredProcedure;
// set up return variable
ret = cmd.Parameters.Add( "id_new", // name
OracleDbType.Decimal ); // type
ret.Direction = ParameterDirection.ReturnValue;
// pass in original id
cmd.Parameters.Add( "id", // name
OracleDbType.Decimal, // type
id, // value
ParameterDirection.Input ); // direction
cmd.ExecuteNonQuery();
if ( ret.Value != null ){
// ai_id_new = (int) ret.Value;
// ai_id_new = (OracleDbType.Decimal ret.Value;
// ai_id_new = (int)(decimal) ret.Value;
// ai_id_new_d = (decimal) ret.Value;
// ai_id_new = (int)(Int32) ret.Value;
// ai_id_new = (Int32) ret.Value;
ai_id_new = int.Parse(ret.Value.ToString());
}
You can see all of the casts that I had to comment out. The last line works, but I don't like it:
ai_id_new = int.Parse(ret.Value.ToString());
Does anyone know what the proper cast is for the ret.Value Object?? to get it assigned back to a C# int?
Thanks,
David