Link to home
Start Free TrialLog in
Avatar of Ryan Smith
Ryan SmithFlag for United States of America

asked on

Populate Listbox using excel spreadsheet column VB.net

Good Afternoon,

I'm trying to populate a listbox in VB.net using a excel spreadsheet column. In my code below it gives me an error saying the 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine"

Imports System.Data.OleDb
Imports System.Data
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        OpenFileDialog1.Title = "Please Select a File"
        OpenFileDialog1.FileName = ""
        OpenFileDialog1.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.Desktop
        OpenFileDialog1.ShowDialog()

        Try
            Dim MyConnection As System.Data.OleDb.OleDbConnection
            Dim DtSet As System.Data.DataSet
            Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
            MyConnection = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source='" & OpenFileDialog1.FileName & "';" & "Extended Properties=""Excel 12.0;HDR=YES;""")
            MyCommand = New System.Data.OleDb.OleDbDataAdapter("select * from [SEA$A:A]", MyConnection)
            MyCommand.TableMappings.Add("Table", "TestTable")

            DtSet = New System.Data.DataSet
            MyCommand.Fill(DtSet)
            ComboBox1.DataSource = DtSet.Tables("TEAML")


            MyConnection.Close()
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub

End Class

Open in new window


User generated image
Avatar of lludden
lludden
Flag of United States of America image

If you don't have access installed, download and install the runtime version.  It will install the driver for you.
could it be related to 32/64 bits?

give a try to the free LINQ-to-Excel tool : http://emoreau.com/Entries/Articles/2013/07/A-free-LINQ-to-Excel-and-CSV-provider.aspx
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Ryan Smith

ASKER

Thanks