Hello all,
Here's the setup: I have a spreadsheet that I am supposed to read several sheets, filter on a date field and send out email notices to the appropriate persons based on the filtered data. I have implemented the solution and it worked fine...until it didn't.
The problem is the date in Excel. Here's basically how I read the data:
1) I use OleDb to get all of the data from a spreadsheet via SQL.
2) Build an in-memory datatable to hold the appropriate data.
3) Loop through the data from step 1 and add it to the datatable from step 2. Unfortunately I have to do this because there is a header on each spreadsheet, so I can't just use the data as-is. I have to start reading the data at line 6 or so.
The problem occurs when I try to add the date from Excel to the date field in the in-memory datatable. It was working fine, but now when the attempt to add the date is made it fails with an "invalid date" error. I checked with a breakpoint and a watch, and the date from Excel is no longer being pulled in as a date, but the underlying numeric code that Excel uses to represent dates internally. For example, the date "5/31/2008" is represented as 39599 "behind the scenes", and it is this number that is being pulled by the SQL query, not the date. So when I try to add this to the datatable, it fails.
I have tried changing the format on the date in Excel, but if I change it to Text for example, it then just displays the 39599.
Any ideas? I can of course post code if necessary.
I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
Here's the setup: I have a spreadsheet that I am supposed to read several sheets, filter on a date field and send out email notices to the appropriate persons based on the filtered data. I have implemented the solution and it worked fine...until it didn't.
The problem is the date in Excel. Here's basically how I read the data:
1) I use OleDb to get all of the data from a spreadsheet via SQL.
2) Build an in-memory datatable to hold the appropriate data.
3) Loop through the data from step 1 and add it to the datatable from step 2. Unfortunately I have to do this because there is a header on each spreadsheet, so I can't just use the data as-is. I have to start reading the data at line 6 or so.
The problem occurs when I try to add the date from Excel to the date field in the in-memory datatable. It was working fine, but now when the attempt to add the date is made it fails with an "invalid date" error. I checked with a breakpoint and a watch, and the date from Excel is no longer being pulled in as a date, but the underlying numeric code that Excel uses to represent dates internally. For example, the date "5/31/2008" is represented as 39599 "behind the scenes", and it is this number that is being pulled by the SQL query, not the date. So when I try to add this to the datatable, it fails.
I have tried changing the format on the date in Excel, but if I change it to Text for example, it then just displays the 39599.
Any ideas? I can of course post code if necessary.
I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!