Click here to Skip to main content
15,916,949 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
while Reading Data from Excel

in some file it returning Date values wrong

for eg. returnig 30-10-2014 12:00 PM as 30-10-02014 12:00 PM
Posted
Comments
CHill60 23-Feb-15 9:54am    
We can't see your screen, examine your HDD or read your mind. Post the code that you are using to read this data
Salman622 23-Feb-15 9:59am    
below is the code for read data
string SourceConstr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + OtherPath.Text + ";Extended Properties= 'Excel 12.0;'";
OleDbConnection con1 = new OleDbConnection(SourceConstr);
con1.Open();
string query = "Select * from [" + OtherSheet.Text + "$]";
DataTable exceltable = new DataTable();
OleDbDataAdapter data = new OleDbDataAdapter(query, con1);
data.Fill(exceltable);
con1.Close();

Its Reading Data PRoper but the problem comes at date column
as i have given example above
ZurdoDev 23-Feb-15 9:59am    
Why is it doing that?
Salman622 23-Feb-15 10:02am    
no idea...

1 solution

Start by looking at the data source: the most likely reason is "finger trouble" from the user when he input the date.
That looks like a string based date representation, rather than a date based item. So read them, then loop through and see if any of them fail a TryParseExact("dd-MM-yyyy hh:mm tt", ... If they do, that's the problem.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900