I am trying to save some double values from my .NET project to MS Access using adodb. If I have uninitialized values I want to save Double.MinValue as a default value into my access db.
The problem is that the range differs in .NET and in Access. For .NET for example the minvalue is
-1.79769313486232e308
and for MS Access the minvalue is
-1.79769313486231E308
can anybody tell me why there is a difference because both are using 8 bytes ... or is there any workaround for my problem. I want to make sure that my users are able to use the full range of Double. Because they won't know that they are "not allowed" to use Double.MinValue ...
Thanks for help in advance!
okay I checked it again and now I have to realize that I am at fault here. The numbers posted above are wrong. For both its the value
-1.7976931348623157e308.
When I asked the question I viewed an untrustworthy source. The problem is that upon converting Double.MinValue to a string the resulting string is "-1.79769313486232e308" and converting it back to double results in an OverflowException.
You can test this with following snippet
double dblVal = Double.MinValue;
string strVal = dblVal.ToString();
dblVal = Convert.ToDouble(strVal);
Hence I am sending an sql query in order to store the value in access I am doing this transformation..
Next time I should check my sources better (: It seems impossible to send Double.MinValue via sql statement to access. I did a workaround in my AccessInterface.
(Note that this original answer was based on the premise of the question that there WAS a discrepancy between the minimum Double values available in .NET and Access. As stated in the other answer from the question owner, that is actually not true.)
My guess would be that the discrepancy is simply an obscure implementation detail. The VBA/VB6 code base is much older than the .NET code base and the people who built VBA/VB6 may have either
0.00000000000001
of precision into the range, orDouble
range was reduced by that miniscule amount.Software design sometimes involves trade-offs, so perhaps that last 0.00000000000001
was sacrificed for some other benefit. The true answer may be lost in the mists of time.
Edit re: statement in other answer
It seems impossible to send Double.MinValue via sql statement to access.
Although it may not be possible to create a SQL statement with a string literal containing Double.MinValue
by simply invoking .ToString()
on it, this code definitely does work (tested with an Access 2010 database):
using (var cmd = new OleDbCommand())
{
cmd.Connection = con;
cmd.CommandText = "INSERT INTO DoubleTest (DoubleField) VALUES (?)";
cmd.Parameters.AddWithValue("?", Double.MinValue);
cmd.ExecuteNonQuery();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With