468,107 Members | 1,324 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,107 developers. It's quick & easy.

Reading Excel

102 64KB
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
0 734

Post your reply

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

Similar topics

1 post views Thread by Hemanth | last post: by
6 posts views Thread by simchajoy2000 | last post: by
9 posts views Thread by dba123 | last post: by
3 posts views Thread by Brad | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.