I am using MS Access and VB .NET 2005 (the same problem happens in VB.NET
2008).
I am reading from a query using DataReader (the same problem happens if I
use OLEDBDataAdapte r).
When I run the query in Access, the value for Cash = 830.00499999999 9, SC =
1692.5 and Profit = -862.49500000000 1.
Cash = SC + Profit.
But when I read the value from the program, this is what I got:
Cash = 830.00000000048 9
SC = 1692.5
Profit = -862.49999999951 1.
Why this difference and how can I fix it ?
Thank you.
Here are the codes:
Dim m_cmd As OleDb.OleDbComm and
Dim m_dr As OleDb.OleDbData Reader
Dim sSQL As String
m_cmd = New OleDb.OleDbComm and
With m_cmd
.Connection = adoConOLE
.CommandText = "select Cash,Profit from myQuery where Account =
'123'"
End With
m_dr = m_cmd.ExecuteRe ader()
If m_dr.Read Then
sSQL = sSQL & " " & m_dr.Item("Cash ") --this returns
830.00000000048 9 instead of 830.00499999999 9 when I run it from Access
sSQL = sSQL & " " & m_dr.Item("SC") --this returns 1692.5,
which is the same as when I run it on Access
sSQL = sSQL & " " & m_dr.Item("Prof it") --this
returns -862.49999999951 1 instead of -862.49500000000 1 when I run it from
Access
End If
2008).
I am reading from a query using DataReader (the same problem happens if I
use OLEDBDataAdapte r).
When I run the query in Access, the value for Cash = 830.00499999999 9, SC =
1692.5 and Profit = -862.49500000000 1.
Cash = SC + Profit.
But when I read the value from the program, this is what I got:
Cash = 830.00000000048 9
SC = 1692.5
Profit = -862.49999999951 1.
Why this difference and how can I fix it ?
Thank you.
Here are the codes:
Dim m_cmd As OleDb.OleDbComm and
Dim m_dr As OleDb.OleDbData Reader
Dim sSQL As String
m_cmd = New OleDb.OleDbComm and
With m_cmd
.Connection = adoConOLE
.CommandText = "select Cash,Profit from myQuery where Account =
'123'"
End With
m_dr = m_cmd.ExecuteRe ader()
If m_dr.Read Then
sSQL = sSQL & " " & m_dr.Item("Cash ") --this returns
830.00000000048 9 instead of 830.00499999999 9 when I run it from Access
sSQL = sSQL & " " & m_dr.Item("SC") --this returns 1692.5,
which is the same as when I run it on Access
sSQL = sSQL & " " & m_dr.Item("Prof it") --this
returns -862.49999999951 1 instead of -862.49500000000 1 when I run it from
Access
End If
Comment