Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi,

I have created a windows form application in which am displaying data in datagridview from ms access 365 in vb.net using oledb connection.

Please suggest me code in vb.net to get data from ms access 365.



Thanks & Regards,
Saurav Sinha

What I have tried:

Dim cn As OleDb.OleDbConnection
        Dim cmd As OleDb.OleDbCommand
        Dim ds As DataSet
        Dim da As OleDbDataAdapter
        Dim tables As DataTableCollection
        Dim source1 As New BindingSource

        cn = New OleDbConnection

        cn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\MsAccess.accdb;"

        Try

            ds = New DataSet
            tables = ds.Tables
            cn.Open()
            da = New OleDbDataAdapter("SELECT * FROM [EmpData]", cn)
            da.Fill(ds)
            cn.Close()
            Dim view As New DataView(tables(0))
            source1.DataSource = view
            DataGridView1.DataSource = view

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
Posted
Updated 4-Aug-20 4:02am
v2
Comments
Maciej Los 4-Aug-20 9:42am    
What's wrong with your code?
yash1507 4-Aug-20 9:58am    
Getting error message
The ‘Microsoft.ACE.OLEDB.12.0’ provider is not registered on the local machine
Richard MacCutchan 4-Aug-20 10:08am    
You are clearly trying to use cn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\MsAccess.accdb;". So, did you install it first?

1 solution

Start by checking your message box: what does it say?

If that isn't helpful, use the debugger to check the InnerException property whiuch may have more info.

If that isn't helpful wither, check you have the right redistributable engine components installed: Download Microsoft Access Database Engine 2016 Redistributable from Official Microsoft Download Center[^]
There are different versions for 32- and 64- bit apps: you will need to install and distribute the appropriate version for your app configuration, if you want it to work.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900