Yes I'm sure the data is reliable.
In my test file I have 2 columns which have their cell format set to dd/mm/yyyy.
When I attempt to read the data from the first column it always returns the correct data but the second column is sometimes empty.
Here is how my code looks:
Code:
string connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + FullyQualifiedFilePath + ";Extended Properties=\"Excel 8.0;HDR=No\"";
System.Data.OleDb.OleDbConnection oledbConn = new System.Data.OleDb.OleDbConnection(connString);
try
{
oledbConn.Open();
OleDbCommand cmd = new OleDbCommand("SELECT * FROM [" + workSheetName + "]", oledbConn);
OleDbDataAdapter oleda = new OleDbDataAdapter();
oleda.SelectCommand = cmd;
DataSet ds = new DataSet();
DataTable dt = new DataTable("ServiceData");
ds.Tables.Add(dt);
oleda.Fill(dt);
foreach (DataRow r in dt.Rows)
{
string rowData = string.Empty; ;
foreach (object o in r.ItemArray)
{
rowData += o.ToString();
}
}
If I put a breakpoint within the foreach loop and then query the first date element I get the correct results as below:
Code:
? r[16]
{26/02/2010 13:52:47}
Date: {26/02/2010 00:00:00}
Day: 26
DayOfWeek: Friday
DayOfYear: 57
Hour: 13
Kind: Unspecified
Millisecond: 750
Minute: 52
Month: 2
Second: 47
Ticks: 634027891677500000
TimeOfDay: {13:52:47.7500000}
Year: 2010
but the second date column should read 07/01/2005 but is empty as below:
Just to make this behaviour really strange, if I do the same query on the third row I get the correct results from both fields although the second date is returned as a string data type rather than a date.
Code:
? r[16]
{26/02/2010 13:19:05}
Date: {26/02/2010 00:00:00}
Day: 26
DayOfWeek: Friday
DayOfYear: 57
Hour: 13
Kind: Unspecified
Millisecond: 193
Minute: 19
Month: 2
Second: 5
Ticks: 634027871451930000
TimeOfDay: {13:19:05.1930000}
Year: 2010
? r[17]
"10/03/2007"
I have triple checked the format of each of the date columns is the same for all cells, the only difference is that the first date column incldues the time element in the data.
Here's the first 3 rows from my data file:
Code:
1 M C C 13 K C F W GD UK W 0 X F E915 26/02/2010 01:00:00 07/01/2005
2 M D M 24 T R R W GD UK S 1 Y E E915 26/02/2010 02:30:00 01/03/2004
I'm completely stumped by this behaviour, any thoughts ?
TIA
Smeat