Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OleDb Excel : No value given for one or more required parameters

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.

like image 612
Oflocet Avatar asked Dec 16 '22 03:12

Oflocet


1 Answers

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.

like image 190
Joe Avatar answered Dec 18 '22 16:12

Joe