Skip to Main Content

ODP.NET

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Parameter.Value proper cast with c# oracle number to c# int??

10626Jul 9 2004 — edited Jul 9 2004
Hello,
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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 6 2004
Added on Jul 9 2004
1 comment
2,664 views