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!

Problem with reading values with a lot of decimal places

BerndLOct 16 2018 — edited Oct 29 2018

I'm having problems reading data from queries producing many decimal places. What is the recommended way to read such data?

private static void OracleDecimalReaderTest()

{

    var csb = new OracleConnectionStringBuilder();

    csb.Add("Data Source", "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=xxxxx)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=xxxxx)))");

    csb.Add("User Id", "xxxxx");

    csb.Add("Password", "xxxxx");

    try

    {

        using (var connection = new OracleConnection())

        using (var command = connection.CreateCommand())

        {

            connection.ConnectionString = csb.ConnectionString;

            connection.Open();

            Console.WriteLine($"Oracle version: {connection.ServerVersion}");

            Console.WriteLine($"Assembly name: {System.Reflection.Assembly.GetAssembly(typeof(OracleConnection)).FullName}");

            command.CommandText = @"

SELECT

  1 / 3 AS value

FROM

  dual ";

                using (var reader = command.ExecuteReader())

                {

                    while (reader.Read())

                    {

                        var value = reader.GetValue(0);

                        Console.WriteLine(value); // never get this far

                    }

                }

            }

        }

    catch (Exception ex)

    {

        Console.WriteLine(ex.Message + "\n" + ex.StackTrace);

    }

}

Result:

Oracle version: 12.1.0.2.0

Assembly name: Oracle.ManagedDataAccess, Version=4.122.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342

Die angegebene Umwandlung ist ungültig. (Specified cast is not valid.)

   bei Oracle.ManagedDataAccess.Client.OracleDataReader.GetDecimal(Int32 i)

   bei Oracle.ManagedDataAccess.Client.OracleDataReader.GetValue(Int32 i)

   bei Konsolentest.Program.OracleDecimalReaderTest() in D:\Eigene Dateien\Visual Studio Projekte\Konsolentest\Konsolentest\Program.cs:Zeile 267.

Any ideas?

Thanks, Bernd

This post has been answered by Alex Keh-Oracle on Oct 16 2018
Jump to Answer
Comments
Post Details
Added on Oct 16 2018
2 comments
3,069 views