i am trying to fetch some data from an excel file, the issue was that i read the first row as data so i decided to change the HDR in my connectionString to Yes but after that my program end up with the exception named in the topic title.
Here is my code and my query :
Calling :
DataTable dt = Utils.queryXlsFile(Qry, dbConnection);
The queryXlsFile method :
public static DataTable queryXlsFile(String query, OleDbConnection dbConnection)
{
OleDbDataAdapter dbCommand = new OleDbDataAdapter(query, dbConnection);
DataTable dt = new DataTable();
dbCommand.Fill(dt);
return dt;
}
And my query :
select top 10 * FROM [PERSONNE$] WHERE (((([F1] LIKE '% prénom %') OR ([F1] LIKE '% prénom')) OR ([F1] LIKE '%-prénom')))
My connection string seems to be good since i can open the connection with the file.
Thanks in advance for your help.
If you have HDR=No, the column names will be auto-generated as F1, F2, ...
If you have HDR=Yes, the column names will be taken from the header row of your spreadsheet.
You need to replace "F1" in your query by the field name from your header row.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With