ITSourceCode.com

We Exist to Provide 100% Free Source Code and Tutorials

Custom Search

03-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
Facebook Comments

Check Your Domain Ranking

Leave a Reply

Your email address will not be published. Required fields are marked *

ITSourceCode.com © 2016 Frontier Theme

Subscribe For Latest Updates

Signup for our newsletter and get notified when we publish new articles for free!