In my code I was using System.Data.OracleClient for ora database connection. I would like to replace this library (because it is obsolete) with Oracle.DataAccess. Unfortunately I found that DataRow.Field() throws InvalidCastException. Same behavior is with (decimal)x.Rows[0]["COLUME_NAME"]. I do not have this issue with System.Data.OracleClient.
Here is code example
using (var oracleConnection = new OracleConnection(connectionString))
{
using (var command = new OracleCommand("select * from tr", oracleConnection))
{
var result = new DataTable();
var adapter = new OracleDataAdapter(command);
adapter.Fill(result);
Console.WriteLine(result.Rows[0].Field<decimal>("TR_SEQ_NUM"));
//Console.WriteLine((decimal)result.Rows[0]["TR_SEQ_NUM"]);
}
}
TR_SEQ_NUM has NUMBER(8,0) datatype and full exception is:
System.InvalidCastException: Specified cast is not valid.
at System.Data.DataRowExtensions.UnboxT`1.ValueField(Object value)
Code example working with System.Data.OracleClient but not with Oracle.DataAccess
I know that I can use Convert.ChangeType but I wonder if there is some way to have same behavior as with System.Data.OracleClient. Refactoring of all of my code will too much time expensive.