title: How to read .xlsx and .xls files using C# and OleDbConnection?
body: <p>Previously I was using <code>ExcelPackage</code> to read data out of a .xlsx file. That was working fine but then I realized that <code>ExcelPackage</code> doesn't work with the old .xls format. So I upgraded to using <code>OleDbConnection</code> instead of <code>ExcelPackage</code> like this:</p>
  
  <pre>var file = HttpContext.Current.Request.Files[0];
  DataTable sheetData = new DataTable();
  string connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
      file.FileName + "; Jet OLEDB:Engine Type=5;Extended Properties=\"Excel 8.0;\"";
  
  using (OleDbConnection conn = new OleDbConnection(connStr))
  {
      conn.Open();
      DataTable dtSchema = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
      string sheetName = dtSchema.Rows[0].Field("TABLE_NAME");
      OleDbDataAdapter sheetAdapter = new OleDbDataAdapter("select * from [" + sheetName + "]", conn);
      sheetAdapter.Fill(sheetData);
  }</pre>
  
  <p>Basically just trying to read the first spreadsheet there. But I get this error in the exception:</p>
  
  <p><code>Cannot update.  Database or object is read-only.</code></p>
  
  <p>What am I doing wrong? Is there some type of update operation hidden in there?</p>