1

I am connecting an access database to a datagrid view on vb and I am encountering an error

"Additional information: The 'Microsoft.ACE.OLEDB.12.0Data Source = CUBSDatabase.accdb' provider is not registered on the local machine."

I am using visual studio version 2015, language visual basic. My access database is saved in the bin in the debug folder

This is my code so far; Any idea how to get rid of the error? The error renders on the line // adt.Fill(datatable)

Imports System.Data.OleDb

Public Class Form1
    Dim dbconn As New OleDbConnection
    Dim adt As New OleDbDataAdapter
    Dim ds As New DataSet

    Dim datatable As New DataTable
    Dim cmd As New OleDbCommand


        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
   dbconn.ConenctionString = ("Provider=Microsoft.ACE.OLEDB.12.0" &
"Data Source = CUBSDatabase.accdb")
showData()

    Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click

        adt = New OleDbDataAdapter("insert into Student (FName, SName, Attendance, CA1, CA2, FinalExam) values ( '" & txtFName.Text & "','" & txtSName.Text & "',  '" & txtAttendance.Text & "', '" & txtCA1.Text & "', '" & txtCA2.Text & "', '" & txtFinalExam.Text & "', )", dbconn)

        adt.Fill(ds)
        ds = New DataSet
        MsgBox("Saved")
    End Sub

    Private Sub showData()
        Dim dbcommand As String
        dbcommand = "SELECT * FROM Students"
        adt = New OleDbDataAdapter(dbcommand, dbconn)
        datatable = New DataTable
        adt.Fill(datatable)
        DataGridView1.DataSource = datatable

    End Sub
End Class
Eimear Brady
  • 21
  • 1
  • 4

2 Answers2

1

Maybe you just forgot a semicolon in your code, after your provider name, since normally you should have something like

Provider=Microsoft.ACE.OLEDB.12.0;Data Source=...

If that's not your case, as per this answer to a similar question, you need to install the provider on your machine; as a preliminary check, you can follow another answer to the same question and see wheter you already have the dll including your provider, i.e. ACEOLEDB.DLL, at one of these paths:

  • C:\Program Files\Common Files\Microsoft Shared\OFFICE14
  • C:\Program Files (x86)\Common Files\Microsoft Shared\OFFICE14

Of course you can adapt those paths to the Office version you have on your machine, which are listed in this answer, e.g.

  • Office 2007 12
  • Office 2010 14
  • Office 2013 15
  • Office 2016 16


EDIT: the following won't apply because Jet won't handle accdb files.

Last but not least, if you don't feel like installing anything or you want to perform a quick check of your code functionality, you can rewrite your connection string to use an older (legacy, perhaps despised) provider, i.e. Jet, which is included in Windows:

dbconn.ConenctionString = ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source = CUBSDatabase.accdb")

Of course there's a difference in terms of efficiency between the two.

Francesco B.
  • 2,729
  • 4
  • 25
  • 37
0

Use this format.

Dim cons As String = "provider= Microsoft.ACE.OLEDB.12.0; Data Source=D:\Users\rjimenez\Documents\QAdatabase.mdb"

but of you still got an error. Download AccessDatabaseEngine

Hope it will works!