How to get column names from Excel using OLEDB query if column name does not start from the first row

I ran into two problems in OLEDB request

(problem 1)

I need to get the column names of a user loaded excel sheet. My connection string for excel

connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+fileNameAndPath+";
Extended Properties=\"Excel 8.0;HDR=YES;IMEX=1\"";

Then i will use this command

connection.Open();

DataTable schemaTable = connection.GetSchema("Columns");
Taking column name from each datarow like this
string name = (string)row["COLUMN_NAME"];

It works fine if the column name is present in the first row of excel. But this column name will be designated as "F1, F2, ....." if the column name row does not start on the first row. How can i solve this? is there any way to indicate in the query which row to get the column names from?

(problem 2)

Like the column heading, I need to select data from a specific range from excel. for example, they take data from line 3 to line 12. Therefore, I used this query,

Select RepName, Country from [Sheet1$3:12].

, " ".

?

, , ?

+3
1

1 OLEDB, Excel , , , , F1 ..

- interop , OLEDB interop.

+1

All Articles