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

1

5

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.

Boatright answered 7/3, 2012 at 8:57 Comment(0)
R
13

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.

Renick answered 7/3, 2012 at 9:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.