title: Best /Fastest way to read an Excel Sheet into a DataTable?
body: <p>I'm hoping someone here can point me in the right direction - I'm trying to create a fairly robust utility program to read the data from an Excel sheet (may be .xls OR .xlsx) into a DataTable as quickly and leanly as possible.</p>
  
  <p>I came up with this routine in VB (although I'd be just as happy with a good C# answer):</p>
  
  <pre><code>Public Shared Function ReadExcelIntoDataTable(ByVal FileName As String, ByVal SheetName As String) As DataTable
      Dim RetVal As New DataTable
  
      Dim strConnString As String
      strConnString = "Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DBQ=" &amp; FileName &amp; ";"
  
      Dim strSQL As String 
      strSQL = "SELECT * FROM [" &amp; SheetName &amp; "$]"
  
      Dim y As New Odbc.OdbcDataAdapter(strSQL, strConnString)
  
      y.Fill(RetVal)
  
      Return RetVal
  
  End Function
  </code></pre>
  
  <p>I'm wondering if this is the best way to do it or if there are better / more efficent ways (or just more intelligent ways - Maybe Linq / native .Net providers) to use instead?</p>
  
  <p>ALSO, just a quick and silly additional question - Do I need to include code such as <code>y.Dispose()</code> and <code>y = Nothing</code> or will that be taken care of since the variable should die at the end of the routine, right??</p>
  
  <p>Thanks!!</p>