title: Excel to DataTable Error in c#
body: <p>I have a strange problem,<br>
  when i try to open and load excel data to a DataTable,<br>
  some data in excel sheet loads but some data doesn't load,<br>
  what is the problem,<br>
  can you help me.<br>
  I added GetExcelData function,<br>
  please look at this code,<br>
  and please tell me what is the problem.  </p>
  
  <pre><code>GROUP      CLASS       TYPE      C1       C2       C3       C4      C4       C5
  M1         10          A         D        B        D        A       A        D
  M1         10          B         C        D        E        E       D        D
  M2         11          A         D        D        D        D       D        E
  M2         11          B         C        D        E        D       E        A
  </code></pre>
  
  <p>Above i placed the sample sheet.<br>
  it copies only datas that are in GROUP, CLASS AND TYPE columns.<br>
  But strange is that in some excel files this error doesn't occur,<br>
  and i didn't find the answer, decided to ask it here.</p>
  
  <pre><code>public DataTable GetExcelData(string fileName, string sheetName)
      {
          string sql = "";
          OleDbConnection conn = new OleDbConnection();
          OleDbCommand command;
          OleDbDataAdapter adapter = new OleDbDataAdapter();
          DataTable dt = new DataTable();
          command = conn.CreateCommand();
          string excel_file = fileName;
          string excel_type = System.IO.Path.GetExtension(excel_file);
          string connstr = ""; 
  
          if(excel_type=="XLSX")
              connstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileName + ";Extended Properties=Excel 8.0";
          else
              connstr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" +fileName + ";Extended Properties='Excel 12.0;IMEX=1; HDR=YES'";
  
          conn.ConnectionString = connstr;
          sql = "SELECT * FROM [" + sheetName + "$]";
  
          command.CommandText = sql;
          adapter.SelectCommand = command;
          adapter.Fill(dt);
  
          return dt;
      }
  </code></pre>