In VB.Net, why OleDataReader GetDecimal() function returns only integer part?
When I run following code on VB.Net
(Visual Studio 2019) a get 789 and never I receive 789.1234. Decimal part il always missing !
Imports System.Data.OleDb
Dim cs = "Provider=PostgreSQL OLE DB Provider;" _
& "DataSource=127.0.0.1;" _
& "location=extraits;" _
& "User ID=postgres;" _
& "Password='Sp1r1tus'"
Dim oleconx = New OleDbConnection(cs)
Dim cmd = New OleDbCommand("SELECT 789.1234 as account", oleconx)
Dim rxSheet = cmd.ExecuteReader()
Dim n = rxSheet.GetOrdinal("account")
Dim dAccount = rxSheet.GetDecimal(n)
it is same thing if I use following code
Dim dAccount = rxSheet("account")
Variable dAccount
contains 789 ! Decimal part is lost !
In real situation (previous code is only a simple code to explain the problem), the only solution I have found to obtain complete decimal number using same code is to change SQL SELECT command
SELECT account * 1000 as account
and to write folloging VB.Net code
Dim dAccount as Decimal = rxSheet("account") / 1000
But this is a workaround.
I have just installed Postgres 14.1 using standard Setup exe program . Before this version, I use version 8.4 on same PC on Windows 10. Perhaps some DLL are not installed in correct place (as libpq.dll).
This problem already existed with version 8.4.
Can some body help me ?
I have posted this bug on PostGres but they responded following
PostgreSQL does not ship a built-in OLE DB provider. You need to contact the authors of your OLE DB driver.
Is there a solution to my issue ?
Who is responsible PostGres or Microsoft ?
Solution 1:
I've tried the scenario with Intellisoft OLEDB Provider for PostgreSQL (PGNP), and it worked as expected. I had to slightly change the connection string, and add line containing rxSheet.Read(). Here is copy of working code:
Dim cs = "Provider=PGNP.1;" _
& "Data Source=127.0.0.1;" _
& "Initial Catalog=postgres;" _
& "User ID=postgres;" _
& "Password=123!"
Dim oleconx = New OleDbConnection(cs)
oleconx.Open()
Dim cmd = New OleDbCommand("SELECT 789.1234 as account", oleconx)
Dim rxSheet = cmd.ExecuteReader()
Dim n = rxSheet.GetOrdinal("account")
While rxSheet.Read()
Dim dAccount = rxSheet.GetDecimal(n)
Console.WriteLine("dAccount={0}", dAccount)
End While
and here is the result: dAccount=789.1234