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“.
After that, the “Add New Item” form will pop up. Name the module “mod_connection” and hit “Add“.
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:
It is the most stable and recent driver we could find; 8 however, if you have issues with Oracle connectivity or other problems, you may consider replacing the 10.