1

When a database column contains number like 0.11212121212121356500008888888888874343468766, it can't be fit to DataRow's generated Decimal-type column. This same applies to DataReader. With DataReader I have solved this with wrapper:

public class OracleDataReaderWrapper : DbDataReader
{
   DbDataReader _realReader;

    public OracleDataReaderWrapper(DbDataReader realReader)
    {
       _realReader = realReader;
    }

//... all other methods

    public override object GetValue(int ordinal)
    {
        if (_realReader is System.Data.OracleClient.OracleDataReader)
        {
            Type fieldType = _realReader.GetFieldType(ordinal);
            if (fieldType == typeof(Decimal))
            {
                return (decimal)((double)((System.Data.OracleClient.OracleNumber)_realReader.GetProviderSpecificValue(ordinal)));
            }
//...

But how can I do something with DataSet, DbDataAdapter? Rewriting all datadapter-Select commands with ROUND or TRUNC is not only wrong, it's out of question because there's already hundreds of places to change it.

NOTE this applies also to ODP.NET. There the type is OracleDecimal instead of OracleNumber. My wrapper is used for both clients.

iqstatic
  • 2,322
  • 3
  • 21
  • 39
char m
  • 7,840
  • 14
  • 68
  • 117

1 Answers1

0
var oracleValue = (OracleDecimal)reader.GetOracleValue(0);
var netValue = (decimal)(OracleDecimal.SetPrecision(oracleValue, 28));

Of course if you are OK with loosing the precision.

Husqvik
  • 5,669
  • 1
  • 19
  • 29
  • Thanks, but datareader has already been solved. Ur can be better and i can look into it, but the question was about DbDataAdapter.Fill or in general populating DataTable. But anyway I think I found a solution myself (I can give it a datareader, see my comments in original post) – char m Sep 09 '15 at 07:57
  • Well the issue is that the OracleDataReader is used in the background when dealing with OracleDataAdapter, making own implementation of DbDataAdapter securing the precision is acceptable for decimal datatype shouldn't be any problem. – Husqvik Sep 09 '15 at 08:26