.net - Date column Error while importing excel in c# -
i reading simple excel file code . excel has 2 column : inputdate[date] , outputdate[date] ..
after importing excel ; 2nd column value not coming ..it coming 42005 ,42006 instead of date .. 2nd column include holidays , needed output
here code
var filename = string.format("d:\\holidaymaster", request.physicalapplicationpath, guid.newguid().tostring().replace("-", string.empty)); var connectionstring = string.format("provider=microsoft.jet.oledb.4.0; data source={0}; extended properties='excel 8.0;;hrd=yes;imex=1'", filename); var adapter = new oledbdataadapter("select * [sheet1$] ", connectionstring); var adapter = new oledbdataadapter("select * [sheet1$]",connectionstring); dataset dsexcel = new dataset(); adapter.fill(dsexcel, "holidaymaster");
this issue 2nd column ..what missing ?if not proper way . right way holidays , date well
ado.net chooses data type based on majority of values in column. that's why converting 2nd column. in case, b5 confuses ado.net
try (code not tested):
change line:
var connectionstring = string.format("provider=microsoft.jet.oledb.4.0; data source={0}; extended properties='excel 8.0;hrd=yes;imex=1'", filename);
to:
var connectionstring = string.format("provider=microsoft.ace.oledb.12.0;data source={0};extended properties='excel 12.0 xml;hdr=yes;imex=1';", filename);
Comments
Post a Comment