By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,640 Members | 2,077 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,640 IT Pros & Developers. It's quick & easy.

Reading Excel

100+
P: 102
I have never read an Excel file and populate a datagridview. Here is my code
Expand|Select|Wrap|Line Numbers
  1.   Try
  2.  
  3.  
  4.             Dim path As String = "C:\\Users\\test\\Desktop\\Event_Logs\\system.xlxs"
  5.             Dim MyConnection As System.Data.OleDb.OleDbConnection
  6.             Dim DataSet As System.Data.DataSet
  7.             Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
  8.             MyConnection = New System.Data.OleDb.OleDbConnection _
  9.                 ("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & path & ";Extended Properties=Excel 12.0;")
  10.             MyCommand = New System.Data.OleDb.OleDbDataAdapter("Select * from [system$]", MyConnection)
  11.  
  12.  
  13.             DataSet = New System.Data.DataSet
  14.             MyCommand.Fill(DataSet)
  15.             DataGridView1.DataSource = DataSet.Tables(0)
  16.  
  17.             MyConnection.Close()
  18.  
  19.         Catch ex As Exception
  20.             MessageBox.Show(ex.ToString)
  21.         End Try
  22.  
  23.  
When the code is executed the
Expand|Select|Wrap|Line Numbers
  1.  MyCommand.Fill(DataSet)
causes the Catch ex as Exception to display

System.Data.OleDb.OleDbException (0x80004005): Cannot update. Database object is read-only.

What am I doing wrong? Thanks in advance.
Sep 12 '16 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.