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

1
503

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.

  1. Private Function strcon() As OleDb.OleDbConnection
  2. Dim strpath As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Application.StartupPath & "\Studdb.accdb"
  3. Return New OleDb.OleDbConnection(strpath)
  4. End Function
  5. Public con As OleDb.OleDbConnection = strcon()

This will be the look of your code inside the module.

  1. Module mod_connection
  2. Private Function strcon() As OleDb.OleDbConnection
  3. Dim strpath As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Application.StartupPath & "\Studdb.accdb"
  4. Return New OleDb.OleDbConnection(strpath)
  5. End Function
  6. Public con As OleDb.OleDbConnection = strcon()
  7. End Module

 

 

Readers might read also:

 

 

 

Facebook Comments
(Visited 122 times, 1 visits today)

1 COMMENT

  1. 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.

LEAVE A REPLY

Please enter your comment!
Please enter your name here