.NET looks like it's formatting a double inside a DataRow in the wrong format, so i can't load it in a second moment. If I store "0.000000001", .NET stores it as "1E-09.0", when it should be "1E-09". So Convert.ToDouble("1E-09.0") returns a FormatException. Here it is the code i use:
// create table
DataTable t = new DataTable("test");
t.Columns.Add("FirstInt", typeof(int));
t.Columns.Add("SecondDouble", typeof(double));
t.Columns.Add("ThirdInt", typeof(int));
// create row data
object[] data = new object[] { 10, 0.000000001, 10 };
// add row data: "0.000000001" is stored as "1E-09.0"
t.Rows.Add(data);
// FormatException is thrown here, since "1E-09.0" should be "1E-09"
double d2 = Convert.ToDouble(t.Rows[0]["SecondDouble"]);
I also tried with cast, but the code throws me "InvalidCastException". The Double.Parse doesn't work as well.
Solution:
// create table
DataTable t = new DataTable("test");
t.Columns.Add("FirstInt", typeof(int));
t.Columns.Add("SecondDouble", typeof(string)); // convert double to string
t.Columns.Add("ThirdInt", typeof(int));
// create row data and convert value to string
double value = 0.0000000001;
string valueString = value.ToString("F9");
object[] data = new object[] { 10, valueString, 10 };
t.Rows.Add(data);
// load data
double d2 = Convert.ToDouble(t.Rows[0]["SecondDouble"]);