简体   繁体   中英

C# cannot get the full DataTable from Excel File

when I'm trying to extract data table from excel file like this:

public void CopyTable(string filename)
{
    var connectionString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0; data source={0}; Extended Properties=Excel 8.0;", filename);

    var adapter = new OleDbDataAdapter("SELECT col_1,   col_2,  col_3,  col_4,  col_5,  col_6    FROM[Sheet1$]", connectionString);
    var ds = new DataSet();

    adapter.Fill(ds, "ReadData");
    m_mainDt = ds.Tables["ReadData"].Copy();
}

I'm getting all the data except from columns 5-6. I'm getting the titles, but not the data

This is what I'm getting

the excel file is .xls

this also happend when i use this query:

 SELECT * FROM[Sheet1$] 

the file was corrupted. I've copied all the table to another file and it worked

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM