c# - While binding a retrieved excel columns in DataSet all columns are retrieved bind except the last column -


i have requirement import excel file in asp.net mvc. importing working needed, there 78 columns in excel file. columns imported except last column.

how retrive last column excel file?

string constring = string.empty;                         if (getfileextension.tolower() == ".xls")                         {                             constring = "provider=microsoft.jet.oledb.4.0;data source=" + getfilename + ";extended properties=\"excel 8.0;hdr=yes;imex=2\""; ;                         }                         else if (getfileextension.tolower() == ".xlsx")                         {                             constring = "provider=microsoft.ace.oledb.12.0;data source=" + getfilename + ";extended properties=\"excel 12.0;hdr=yes;imex=2\"";                         }                         oledbconnection con = new oledbconnection(constring);                         if (con.state == connectionstate.closed) con.open();                         datatable excelsheets = con.getoledbschematable(oledbschemaguid.tables, new object[] { null, null, null, "table" });                         string spreadsheetname = excelsheets.rows[0]["table_name"].tostring();                         string query = "select * [" + spreadsheetname + "]";                         oledbcommand cmd = new oledbcommand(query, con);                         oledbdataadapter da = new oledbdataadapter(cmd);                         dataset ds = new dataset();                         da.fill(ds);                         da.dispose();                         con.close();                         con.dispose(); 

according import excel datatable skipping last column values, may excel or oledb bug.

as workaround, might consider modifying excel sheet add additional column header @ end, no data in column. then, column skipped during import 1 don't need.


Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -