How to connect Microsoft Access database using VB.net

Learn VB.Net Programming in simple and easy steps.




VB.net tutorial for beginner.

Establish a successful connection to a Microsoft Access Database using VB.net




How to connect Microsoft Access database using VB.net programming.


Program
source code:

Public Class Form1
    Dim dbProvider As String
    Dim dbSource As String
    Dim con As New OleDb.OleDbConnection
    Dim sql As String
    Dim ds As New DataSet
    Dim da As OleDb.OleDbDataAdapter
    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
      
        dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
        dbSource = "Data Source =C:\testvb\testcon.mdb"

        con.ConnectionString = dbProvider & dbSource
        con.Open()
        MsgBox("Database is now open")
        sql = "select * from student"
        da = New OleDb.OleDbDataAdapter(sql, con)
        da.Fill(ds, "test")

        DataGridView1.DataSource = ds.Tables("test")

        con.Close()

        MsgBox("Database is now Closed")

    End Sub


End Class