I try to retrieve a whole Excel sheet. Everything seems to be alright but when I put one or more empty rows to the begining of the sheet, they won't be read by OleDbAdapter. Unfortunately I need them because the user tells me (the program) which rows have to be read.
So when the user says, row 2 and 3 have to be read and he inserts an empty row at the begining my program would miss the data because the first row was not read.
This is the way I create the connection strings, depending if it is a xls or xlsx file and if ACE is available:
XLS, ACE available
"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\"" + file + "\";Mode=Read Extended Properties=\"Excel 8.0;HDR=No;IMEX=1;ImportMixedTypes=Text\""
XLS, ACE not available
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\"" + file + "\";Mode=Read;Extended Properties=\"Excel 8.0;HDR=No;IMEX=1;ImportMixedTypes=Text\""
XLSX, ACE needs to be available (same for XLSM, XLSB)
"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\"" + file + "\";Mode=Read;Extended Properties=\"Excel 12.0 Xml;HDR=No;IMEX=1;ImportMixedTypes=Text\""
This is my select:
string select = "SELECT * FROM [" + sheet + "$]";
And this is how I retrieve the data:
OleDbDataAdapter adapter = new OleDbDataAdapter(select, connectionString);
DataTable dt = new DataTable(sheet);
adapter.Fill(dt);
int rowCount = dt.Rows.Count;
int columnCount = dt.Columns.Count;
Edit: Here someone else has the same problem but I don't see differences to my code and I do not get the empty lines.
So my question again: How do I read in empty rows at the beginning?