title: Get Excel data in DataTable
body: <p>I'm currently trying to access data from an Excel file in my C# Code. Thats my try:</p>
  <pre><code>public static void Main(string[] args)
          {
              var filepath= &quot;.../0f351ee0-0e7b-488b-80c5-db5da81f4bb5.xlsx&quot;;
              ReadExcel(file_path, &quot;.xlsx&quot;);
              Console.ReadLine();
          }
      enter code here
          public static DataTable ReadExcel(string fileName, string fileExt)
          {
              string conn = string.Empty;
              DataTable dtexcel = new DataTable();
              if (fileExt.CompareTo(&quot;.xls&quot;) == 0)
                  conn = @&quot;provider=Microsoft.Jet.OLEDB.4.0;Data Source=&quot; + fileName + &quot;;Extended Properties='Excel 8.0;HRD=Yes;IMEX=1';&quot;; //for below excel 2007  
              else
                  conn = @&quot;Provider=Microsoft.ACE.OLEDB.12.0;Data Source=&quot; + fileName + &quot;;Extended Properties='Excel 12.0;HDR=NO';&quot;; //for above excel 2007  
              using (OleDbConnection con = new OleDbConnection(conn))
              {
                  try
                  {
                      OleDbDataAdapter oleAdpt = new OleDbDataAdapter(&quot;select * from [Sheet1$]&quot;, con); //here we read data from sheet1  
                      oleAdpt.Fill(dtexcel); //fill excel data into dataTable  
                  }
                  catch { }
              }
              Console.WriteLine(dtexcel);
            
              return dtexcel;
  </code></pre>
  <p>the problem is that the DataTable is always empty. Where exactly can I solve this problem?</p>