F
fniles
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 OLEDBDataAdapter).
When I run the query in Access, the value for Cash = 830.004999999999, SC =
1692.5 and Profit = -862.495000000001.
Cash = SC + Profit.
But when I read the value from the program, this is what I got:
Cash = 830.000000000489
SC = 1692.5
Profit = -862.499999999511.
Why this difference and how can I fix it ?
Thank you.
Here are the codes:
Dim m_cmd As OleDb.OleDbCommand
Dim m_dr As OleDb.OleDbDataReader
Dim sSQL As String
m_cmd = New OleDb.OleDbCommand
With m_cmd
.Connection = adoConOLE
.CommandText = "select Cash,Profit from myQuery where Account =
'123'"
End With
m_dr = m_cmd.ExecuteReader()
If m_dr.Read Then
sSQL = sSQL & " " & m_dr.Item("Cash") --> this returns
830.000000000489 instead of 830.004999999999 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("Profit") --> this
returns -862.499999999511 instead of -862.495000000001 when I run it from
Access
End If
2008).
I am reading from a query using DataReader (the same problem happens if I
use OLEDBDataAdapter).
When I run the query in Access, the value for Cash = 830.004999999999, SC =
1692.5 and Profit = -862.495000000001.
Cash = SC + Profit.
But when I read the value from the program, this is what I got:
Cash = 830.000000000489
SC = 1692.5
Profit = -862.499999999511.
Why this difference and how can I fix it ?
Thank you.
Here are the codes:
Dim m_cmd As OleDb.OleDbCommand
Dim m_dr As OleDb.OleDbDataReader
Dim sSQL As String
m_cmd = New OleDb.OleDbCommand
With m_cmd
.Connection = adoConOLE
.CommandText = "select Cash,Profit from myQuery where Account =
'123'"
End With
m_dr = m_cmd.ExecuteReader()
If m_dr.Read Then
sSQL = sSQL & " " & m_dr.Item("Cash") --> this returns
830.000000000489 instead of 830.004999999999 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("Profit") --> this
returns -862.499999999511 instead of -862.495000000001 when I run it from
Access
End If