ms jet rounding double values RRS feed

  • Question

  • User189827543 posted


    I am using this code to import data from excel into my application:
        public DataTable Import(string fileName)
                string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileName + "; Extended Properties='Excel 8.0; IMEX=1; HDR=YES'";
                System.Data.OleDb.OleDbDataAdapter dataAdapter = new System.Data.OleDb.OleDbDataAdapter("SELECT * FROM [DATA$]", connectionString);
                DataSet dataSet = new DataSet();
                dataAdapter.Fill(dataSet, "ExcelInfo");
                DataTable dataTable = dataSet.Tables["ExcelInfo"];
                return dataTable;
            catch(Exception e)
                return null;

    When I access the values from the data table, I notice that it contains the formatted values for my cells and not actual values.For certain float/double cells - I am losing precision. Values are being rounded. Any ideas on how I can get around this? Do I have to rewrite this import code to use something other than MS Jet?

    Monday, November 24, 2008 10:12 AM


  • User-1136466523 posted


    <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p> </o:p>

    From your description, it seems that the dataset or datatable’s schema has not defined before you start to transport the data from Excel.

    <o:p> </o:p>

    Try to create a data Table and define each field with the correct data type you want, and then import the data from your Excel file.

    <o:p> </o:p>



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 27, 2008 12:12 AM