Conectar visual basic con excel

  • Thread starter Thread starter Gokrusk
  • Start date Start date
G

Gokrusk

Guest
Tengo el siguiente error conectando visual basic con excel para insertar los de datos de excel en un datagriedview

"El provedor microsoft.ace.oled.16.0 no está registrado en el equipo local"; ya instalé todo lo que he visto en otros posts y nada soluciona


Aquí el código


Imports System.Data.OleDb
Public Class Form1
Dim conn As OleDbConnection
Dim dta As OleDbDataAdapter
Dim dts As DataSet
Dim excel As String
Dim openfiledialog As New OpenFileDialog
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles BT_EXIMPORT.Click
Try

openfiledialog.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.MyDocuments
openfiledialog.Filter = "All files(*.*)|*.*|Excel Files(*.xlsx)|*.xlsx|Xls Files(*.xsl)|*.xls"
If openfiledialog.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK Then
Dim fi As New IO.FileInfo(openfiledialog.FileName)
Dim filename As String = openfiledialog.FileName
excel = fi.FullName
conn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.16.0;Data Source=" + excel + ";Extended Properties = Excel 16.0; Persist Security Info=False")
dta = New OleDbDataAdapter("select * from [sheet1$]", conn)
dts = New DataSet
dta.Fill(dts, "[sheet1$]")
DataGridView1.DataSource = dts
DataGridView1.DataMember = "[sheet1$]"
conn.Close()
End If
Catch ex As Exception
MsgBox(ex.Message)
conn.Close()
End Try

End Sub


End Class

Continue reading...
 
Back
Top