03-Setting Up Connection Between MS Access Database and Visual Basic 2008

This tutorial is all about Setting Up Connection Between MS Access Database and Visual Basic 2008.
Today, i will teach you how to connect Ms Access Database to Visual Basic 2008. When we talk about the connection of Ms Access Database to Visual Basic 2008 it is necessary to use an OLE DB data provider.

 

So, let’s begin:

 

Open the Visual Basic 2008 and create a new Windows Form Application. After creating a Windows Form Application, go to solution explore, right click the name of your project, hit “add” and hit “Module“.
settingupconnection_form1
settingupconnection_form2
After that, the “Add New Item” form will pop up. Name the module “mod_connection” and hit “Add“.
settingupconnection_form3

Now, in the module( “mod_connection” ), set a private function for the connection between Ms Access Database to Visual Basic 2008 and pass it to a public variable as “OleDb.OleDbConnection“. It will look like this.
[vbnet]
Private Function strcon() As OleDb.OleDbConnection
Dim strpath As String = “Provider=Microsoft.ACE.OLEDB.12.0;Data Source=” & Application.StartupPath & “\Studdb.accdb”
Return New OleDb.OleDbConnection(strpath)
End Function
Public con As OleDb.OleDbConnection = strcon()
[/vbnet]
This will be the look of your code inside the module.
[vbnet]
Module mod_connection
Private Function strcon() As OleDb.OleDbConnection
Dim strpath As String = “Provider=Microsoft.ACE.OLEDB.12.0;Data Source=” & Application.StartupPath & “\Studdb.accdb”
Return New OleDb.OleDbConnection(strpath)
End Function
Public con As OleDb.OleDbConnection = strcon()
End Module
[/vbnet]

 

 

Readers might read also:

 

 

 

1 thought on “03-Setting Up Connection Between MS Access Database and Visual Basic 2008”

Leave a Comment