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.
Dim adapter = New OracleDataAdapter(command) With {.SuppressGetDecimalInvalidCastException = True}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'