title: Retrieve column header from specific row in excel using ADO and VB.net
body: <p>I have an app where a user uploads a spreadsheet and specifies the sheetname and row number for the header row. I need the app to extract the column names from that specified row. I was able to get it to work returning the top row. How would i speficy that the column names i want should be on row(x)</p>
  
  <pre><code>     Dim ExcelConn As System.Data.OleDb.OleDbConnection
          Dim ExcelTable As DataTable = Nothing
          Dim dr As DataRow
          Dim sheet_found As Boolean = False
          ExcelConn = New system.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" &amp; file &amp; ";Extended Properties=Excel 12.0;")
          End If
  
          'open the file
          ExcelConn.Open()
          ExcelTable = ExcelConn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, New Object() {Nothing, Nothing, Nothing, "Table"})
  
          'make sure there is a matching sheet name
          For Each dr In ExcelTable.Rows
              If dr("TABLE_NAME").ToString() = sheet &amp; "$" Then
                  sheet_found = True
                  Exit For
              End If
          Next
          If sheet_found = False Then
              MesgBox("the sheet name specified in the header (" + sheet + ") was not found")
              ExcelConn.Close()
              Exit Sub
          Else
              Dim sheet_name As String = Nothing
              sheet_name = "[" &amp; sheet &amp; "$]"
              Dim cmd1 As New System.Data.OleDb.OleDbCommand("Select * From " &amp; sheet_name, ExcelConn)
              Dim da As New OleDbDataAdapter("Select * From " &amp; sheet_name, ExcelConn)
              Dim ds As DataSet = New DataSet()
              Dim dc As DataColumn
              da.Fill(ds)
              For Each dc In ds.Tables(0).Columns 'this returns col names fine from first row. how would i tell it to get names from 2nd or 3rd row, etc. The integer var is passed in. i just need to know how to specify that it is row(x)
                  header_row = LCase(RTrim(header_row + "|" + dc.ColumnName))
              Next
              MsgBox(header_row)
              ExcelConn.Close()
          End If
  </code></pre>