Solved

Populate Listbox using excel spreadsheet column VB.net

Posted on 2013-11-04
4
947 Views
Last Modified: 2013-11-20
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


Error
0
Comment
Question by:AnthonySmithMCP
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 18

Expert Comment

by:lludden
ID: 39622684
If you don't have access installed, download and install the runtime version.  It will install the driver for you.
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 39623148
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
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 39623871
Download and install ACE driver and then change your connection string to use ACE driver instead of JET

http://www.microsoft.com/en-gb/download/details.aspx?id=13255
0
 
LVL 1

Author Comment

by:AnthonySmithMCP
ID: 39662264
Thanks
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question