Oflocet
Oflocet

Reputation: 566

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.

Upvotes: 5

Views: 10193

Answers (1)

to StackOverflow
to StackOverflow

Reputation: 124794

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.

Upvotes: 13

Related Questions