I need to read the values from Excel to DataSet using OleDb Connection. Below is my code.
OleDbCommand excelCommand = new OleDbCommand();
OleDbDataAdapter excelDataAdapter = new OleDbDataAdapter();
string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;
Data Source=" + filelocation + @";Extended Properties=""Excel 8.0; IMEX=1;HDR=NO;""";
OleDbConnection excelConn = new OleDbConnection(connectionString);
excelConn.Open();
excelCommand = new OleDbCommand("SELECT * FROM [Sheet1$]", excelConn);
excelDataAdapter.SelectCommand = excelCommand;
excelDataAdapter.Fill(ds);
While reading I am losing precision in my cell.
E.g.: Excel Cell has value -0.46256613817052
My DataSet has value -0.4625661
Most of my cells in the Excel sheet are of Number type.
How to solve this? Please help.
According to this answer for Microsoft.Jet.OLEDB.4.0 rounding excel data? , if you need to get exact values, you need to use visual studio tools for office.
I have solved the issue using Excel Data Reader/
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