c# - OleDbAdapters doesn't read dates in different formats from single excel column -



c# - OleDbAdapters doesn't read dates in different formats from single excel column -

i reading excel file in application. utilize oledbdataadapter read , datatable store records .xlsx file. have problem reading different date formats single column. column looks that:

2014-02-07 2014-02-05 27.01.2014 19.11.2013 2014-02-07 2014-02-07

my programme loads dates in "yyyy-mm-dd" format , rest of them dbnull.value. there way read whole column strings (so can manipulate them manualy) or forcefulness oledbdataadapter read dates?

thats code:

var filename = string.format(@"c:\28.xlsx"); var connectionstring = string.format(@"provider=microsoft.ace.oledb.12.0;data source=" + filename + ";extended properties='excel 12.0 xml;hdr=no;imex=1'"); var adapter = new oledbdataadapter("select * [sheet1$b12:l]", connectionstring); var ds = new dataset(); adapter.fill(ds, "anynamehere"); system.data.datatable info = ds.tables["anynamehere"]; foreach (datarow row in data.rows) { seek { console.writeline(row.field<datetime>(3).toshortdatestring()); } grab { console.writeline(row.field<string>(3)); } }

oledb figures out column info type based on first row's content (if headers available, 1 after header) , applies rest of rows.

so suggest alter column's info format text rather date/time , deal them on c# side.

c# excel date-formatting oledbdataadapter

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -