Using OleDB to get data from Excel

D

dvd00

Hi people!

I'm using OleDbDataReader to get rows one-by-one from Excel sheet. The
code I'm using to do this:

oConn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=" + name +
";Extended Properties=\"Excel 8.0;HDR=YES;IMEX=1;\"");
oConn.Open();
OleDbCommand oCmd = new OleDbCommand("SELECT * FROM [Sheet1$]",
oConn);
OleDbDataReader oReader = oCmd.ExecuteReader();

while (oReader.Read())
{
//array to store current row
object[] rowValues = new object[oReader.FieldCount];
oReader.GetValues(rowValues);
.....
}

Parameter TypeGuessRow=0. So the problem I'm getting is: values from
column with mixed types is imported with loosing their precision! For
example I have column with values {'9133.13', '87654321', '586472.12',
'a.27'}. First value imported correctly, second and third - are not.
For second I got 8.76543e+007 and for third I got 586472. Fourth value
is also correct. Firstly these cells has "Currency" format, but after
it was changed by user to "Text" without reentering values to the
cells. After this changes my problem had arised. May someone knows how
to fix it - any comments/advices/links appreciated.
 
J

Jamie Collins

(e-mail address removed) (dvd00) wrote ...
oConn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=" + name +
";Extended Properties=\"Excel 8.0;HDR=YES;IMEX=1;\"");
Parameter TypeGuessRow=0.
the problem I'm getting is: values from
column with mixed types is imported with loosing their precision! For
example I have column with values {'9133.13', '87654321', '586472.12',
'a.27'}. First value imported correctly, second and third - are not.
For second I got 8.76543e+007 and for third I got 586472. Fourth value
is also correct. Firstly these cells has "Currency" format, but after
it was changed by user to "Text" without reentering values to the
cells. After this changes my problem had arised.

What happens when you remove

;IMEX=1;

from the connection string?

Jamie.

--
 
J

Jamie Collins

(e-mail address removed) (dvd00) wrote ...
Hi Jamie! You wrote in message

Nothing - the situation is the same.

The reason I asked was that I tested using the data and process as you
described in your original post: I could reproduce the results when
using IMEX=1 in the connection string but when I removed it the
results came out as desired and expected.

I would be happy to re-test if you re-post the data and cell formats
you are using.

Jamie.

--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top