Oledb + excel + HDR = NO. How to make selects?

1

The thing is that I want to make Selects in Excel, in any possible way, I do not value interop since the sheet is dynamic, one day it can have 340 records, another day 20.

What I'm trying to do is something kind:

Select count(*) From [Sheet$] Where id=12312

To give an example. I know that this type of query would not make sense, but to understand us.

  

Example of structure of the table.

The actual table is more complex, has more columns whose names have spaces.

This is the connection I have created and what I have tried so far, but it has not worked, among other similar attempts.     OleDbConnection MyConnection;     OleDbCommand myCommand = new OleDbCommand ();     OleDbDataReader dr;

MyConnection = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source='D:\nombre.xlsx';Extended Properties='Excel 8.0;HDR=NO'");
myCommand.CommandText = "SELECT count(*) FROM [Hoja1$]";
dr = myCommand.ExecuteReader();
while (dr.Read())
{
     resultados.Add(dr.GetString(1)); //List<String> resultados = new List<String>();
}

Any way to filter the data?

    
asked by Aritzbn 12.12.2017 в 16:49
source

1 answer

1

You can use the Excel Interop and access the cells of the sheet with column-column coordinates without having to make sql queries. Look at this example: link

    
answered by 12.12.2017 / 18:38
source