Error importing an excel file into VB.NET

0

Greetings to all, it turns out that I am doing an importer that consists in uploading data from an Excel file to a table made in SQL Server (In an app made in VB.NET), I am adapting a code according to my needs and when importing the Excel file sends me the following error

  

The Microsoft ACE.OLEDB.12.0 provider is not registered on the local machine.

It is worth mentioning that in my PC I have installed office 2016, the visual studio that I use is the VB 2010 Pro, I do not know if that is the reason for my mistake, I appreciate any guidance that you can make me.

Sub excelAsql()
    Dim myFileDialog As New OpenFileDialog()
    Dim xSheet As String = ""
    With myFileDialog
        .Filter = "Archivos de Excel |*.xlsx"
        .Title = "Abrir archivo excel"
        .ShowDialog()
    End With

    If myFileDialog.FileName.ToString <> "" Then
        Try
            Dim ExcelFile As String = myFileDialog.FileName.ToString
            xSheet = InputBox("Nombre de la Hoja", "")
            conn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;" & "data source=" & ExcelFile & "; " & "Extended Properties='Excel 12.0;HDR=Yes'")
            conn.Open()
            da = New OleDbDataAdapter("SELECT * FROM  [" & xSheet & "$]", conn)

            Dim dt As New DataTable
            da.Fill(dt)
            frmLista.DataGridView1.DataSource = dt
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End If
End Sub
    
asked by Silvestre Silva 24.01.2018 в 00:24
source

1 answer

0

Solved (based on my personal experience)!

with Install the following Driver Data Connectivity Components

  • After restarting Visual Studio
  • In the project name right click and "Add reference"
  • Click on the COM tab and Select "Microsoft Office 12.0 Object Library" and Done !!
  • answered by 24.01.2018 / 18:20
    source