0

With some vb.net code I try to retrieve data from an Oracle database (simplified example):

strQuery = "Select 2.3, 2.3/1, 2.3/3.1 From Owner.TableName Where ROWNUM < 10" Dim da As OracleDataAdapter da = New OracleDataAdapter(strQuery, ConnectionString) da.Fill(GetData) 

This results in an "Specified cast is invalid" error.

The 2.3/3.1 is the problem.

I learned from "Specified cast is not valid" when populating DataTable from OracleDataAdapter.Fill() that Oracle works with a higher precision than dot net can handle and that I should use SuppressGetDecimalInvalidCastException in the OracleDataAdapter. But I don't know how to code it in VB.net. Can anyone help me?

Automatic translation from the C# code did not work. The C# code itself did not work for me (probably due to the fact that I don't know how to handle the async stuff) and if I simplify it to

string queryString = "Select 2.3, 3.1 From owner.table"; string connectionString = "Data Source=Data.plant.be/database;User ID=****;Password=****"; var table = new DataTable(); var connection = new OracleConnection(connectionString); var command = new OracleCommand(queryString, connection); var adapter = new OracleDataAdapter(command) { SuppressGetDecimalInvalidCastException = true }; adapter.Fill(table); 

I get error CS0117: OracleDataAdaptor does not contain a definition for SuppressGetDecimalInvalidCastException.

Extra info: As proposed by @Andrew-Morton - thank you Andrew - I wrote:

Dim table = New DataTable() Dim connection = New OracleConnection(ConnectionString) Dim cmd = New OracleCommand(strQuery, connection) Dim adapter = New OracleDataAdapter(cmd) With {.SuppressGetDecimalInvalidCastException = True} adapter.Fill(GetData) 

But I get BC30456: SuppressGetDecimalInvalidCastException is not a member of 'OracleDataAdapter'.

Remark: I have version 19.6 of Oracle.ManagedDataAccess. I could not install package 'Oracle.ManagedDataAccess 21.9.0'. I Get: You are trying to install this package into a project that targets '.NETFramework,Version=v4.5', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.

5
  • Dim adapter = New OracleDataAdapter(command) With {.SuppressGetDecimalInvalidCastException = True} Commented Jan 21, 2023 at 20:07
  • So I wrote this: Dim table = New DataTable() Dim connection = New OracleConnection(ConnectionString) Dim cmd = New OracleCommand(strQuery, connection) Dim adapter = New OracleDataAdapter(cmd) With {.SuppressGetDecimalInvalidCastException = True} adapter.Fill(GetData) But I get BC30456: SuppressGetDecimalInvalidCastException is not a member of 'OracleDataAdapter' Commented Jan 21, 2023 at 21:16
  • Would it be possible for you to update the project to .NET 4.8.1? (You'll need VS2022, I think, otherwise .NET 4.8 works with VS2017 and the code I suggested.) Then you will be able to use the attribute you want to. Otherwise, you will need to use one of the techniques in the other answers to the question you linked to. Commented Jan 22, 2023 at 14:04
  • If you do update the framework, there are guides available telling you about changes, e.g., Runtime Changes for Migration from .NET Framework 4.5 to 4.8. Commented Jan 22, 2023 at 14:10
  • 1
    I did the updates (.NET 4.8 and also Oracle.ManagedDataAccess). Now it works perfect. Thank you very much @AndrewMorton ! Commented Jan 24, 2023 at 18:12

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.