title: Error when trying to read data from Excel in VB.Net
body: <p>I've tried many different routes in being able to build a page that allows the user to choose an excel file and then reads data from that file. So far all I've gotten is errors.</p>
  
  <p>My latest error is: "Cannot update.  Database or object is read-only."</p>
  
  <p>Here is my code:</p>
  
  <pre><code>Protected Sub Upload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Upload.Click
      If (testFile.HasFile) Then
          Dim ds As DataSet
          Dim strFileType As String = System.IO.Path.GetExtension(testFile.FileName).ToString().ToLower()
  
          Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
          Dim MyConnection As System.Data.OleDb.OleDbConnection
          MyConnection = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" &amp; testFile.FileName &amp; ";Extended Properties=""Excel 12.0;HDR=Yes;IMEX=2")
  
          ' Select the data from Sheet1 ([in-house$]) of the workbook.
          MyCommand = New System.Data.OleDb.OleDbDataAdapter("select * from [Sheet1$]", MyConnection)
  
          ds = New System.Data.DataSet
          MyCommand.Fill(ds) - __This is where the error points.__
          grvExcelData.DataSource = ds.Tables(0)
  
      End If
  End Sub
  </code></pre>
  
  <p>Any ideas on why this is being thrown? I'm just trying to output the data to a gridview for now. Later I will need to loop through each cell, but I'm trying one step at a time.</p>
  
  <p>Also, if there's a better way to do this I am completely open to it!</p>
  
  <p>Thanks!</p>