SQL Compact 3.5 versus 3.01
-
Hi, I am having the following problem AFTER converting to VS2008 from VS2005 and SQLCE 3.5 from 3.01: SQL CE db file has a table called Court0 with various columns of type float. I populate the values by copying floats from another table/tables. I do this via ado.net using this code snippet: foreach (DataColumn column in this.mycourtsDataSet1.Tables[tableName].Columns) { string columnName = column.ColumnName.ToString(); string columnValue = aRow[0][columnName].ToString(); object cValue = aRow[0][columnName]; if (columnName.Remove(1) == "T" && !string.IsNullOrEmpty(columnValue)) { // Add the value to the Court0 table. DataRow[] bRow = this.mycourtsDataSet1.Tables["Court0"].Select("BookingPeriod = '" + columnName + "'"); if (bRow.Length > 0) { double colValue = Convert.ToDouble(cValue); //bRow[0][tableName] = Convert.ToInt32(columnValue); ========> bRow[0][tableName] = colValue; <==== colValue is '1055.01' } } } } This works fine in VS2005/CE3.01 BUT not in VS2008/CE3.5 In CE3.5, the value entered into the cell looses it's decimal value. For example, '1055.01' becomes '1055.0' in CE3.5 . Can someone explain to me why the conversion stuffs up in CE3.5 and what do I do to fix it. Thanks,
Glen Harvy
-
Hi, I am having the following problem AFTER converting to VS2008 from VS2005 and SQLCE 3.5 from 3.01: SQL CE db file has a table called Court0 with various columns of type float. I populate the values by copying floats from another table/tables. I do this via ado.net using this code snippet: foreach (DataColumn column in this.mycourtsDataSet1.Tables[tableName].Columns) { string columnName = column.ColumnName.ToString(); string columnValue = aRow[0][columnName].ToString(); object cValue = aRow[0][columnName]; if (columnName.Remove(1) == "T" && !string.IsNullOrEmpty(columnValue)) { // Add the value to the Court0 table. DataRow[] bRow = this.mycourtsDataSet1.Tables["Court0"].Select("BookingPeriod = '" + columnName + "'"); if (bRow.Length > 0) { double colValue = Convert.ToDouble(cValue); //bRow[0][tableName] = Convert.ToInt32(columnValue); ========> bRow[0][tableName] = colValue; <==== colValue is '1055.01' } } } } This works fine in VS2005/CE3.01 BUT not in VS2008/CE3.5 In CE3.5, the value entered into the cell looses it's decimal value. For example, '1055.01' becomes '1055.0' in CE3.5 . Can someone explain to me why the conversion stuffs up in CE3.5 and what do I do to fix it. Thanks,
Glen Harvy
If you need a decimal quantity to retain its decimal representation through storage and manipulation in a program, you should be using decimal data types. Binary floating point types are generally more effective for scientific computation, but they cannot preserve what appear to be simple decimal values. To two decimal places, only the fractions 0.00, 0.25, 0.50 and 0.75 are recorded accurately; the other 96 values are approximations. Binary floating point records fractional values as sums of negative powers of two, that is, 1/2 + 1/4 + 1/8 + 1/16 + 1/32 + ... 0.01's closest approximation is 1/16 + 1/32 + 1/256 + 1/512 + 1/4096 + 1/8192 + 1/65536, to 16 fractional bits. This is 0.0999908447265625. Conversions between different floating point representations can cause significant digits to be lost.
DoEvents: Generating unexpected recursion since 1991
-
If you need a decimal quantity to retain its decimal representation through storage and manipulation in a program, you should be using decimal data types. Binary floating point types are generally more effective for scientific computation, but they cannot preserve what appear to be simple decimal values. To two decimal places, only the fractions 0.00, 0.25, 0.50 and 0.75 are recorded accurately; the other 96 values are approximations. Binary floating point records fractional values as sums of negative powers of two, that is, 1/2 + 1/4 + 1/8 + 1/16 + 1/32 + ... 0.01's closest approximation is 1/16 + 1/32 + 1/256 + 1/512 + 1/4096 + 1/8192 + 1/65536, to 16 fractional bits. This is 0.0999908447265625. Conversions between different floating point representations can cause significant digits to be lost.
DoEvents: Generating unexpected recursion since 1991
Thanks for your response - much appreciated as I'm pulling my hair out down here!! I have changed the SSCE 3.5 to type Money (there is no 'decimal' in SSCE) as well as the dataTable to type decimal. (I have also tried other numeric types as well in my trials and tribulations). Providing I don't execute the following, I don't lose the decimal portion: this.court0TableAdapter1.Update(this.mycourtsDataSet1.Court0); this.mycourtsDataSet1.AcceptChanges(); this.court0TableAdapter1.Fill(this.mycourtsDataSet1.Court0); I'm almost at the stage of using strings to store my data and a hell of a lot of conversions but that seems ludicrous :mad: Somethings changed between VS2005/2008 and CE3.01/CE3.5 :confused: Later ... The problem was with VS2008 not updating the SQLce data engine during conversion. Once I "reconfigured" the dataadapter all was fixed.
Glen Harvy