2

I'm using following code to connect with a Excel file with OleDB:

        Connection = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Path + ";Extended Properties=Excel 12.0;")
        Command = New System.Data.OleDb.OleDbDataAdapter("select * from [Sheet1$]", Connection)
        DataSet = New System.Data.DataSet
        Command.Fill(DataSet)
        Connection.Close()

I would like to get the name of the first excel sheet and put it in a string variable so I can use it in the SQL command. How can I do this?

H3Ls3n
  • 33
  • 5
  • if I remember well it is possible to extract sheet name but not in the exact order as they appear in the file. give a look at this link to start: http://stackoverflow.com/questions/13618224/how-to-get-sheets-name-from-excel-2007-xlsx-using-vb-net-or-c-sharp – tezzo Jul 31 '15 at 09:39
  • this is an old answer... it seems that OLEDB does not preserve the sheet order as they were in Excel: http://stackoverflow.com/questions/1164698/using-excel-oledb-to-get-sheet-names-in-sheet-order – tezzo Jul 31 '15 at 09:42

0 Answers0