Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Home > TechHelp > Directory > VB.NET > Connect to Access DB
Connect to Access DB
By Alex Hedley   12 years ago

Intermediate

Create a blank Form and add a DataGridView on to it.

Import the Oledb information.

'Imports System.Data

Imports System.Data.OleDb


 

Now in your code, create some variable to store the information you will be using later.

Dim dbProvider As String

Dim dbSource As String

  

Dim dbPathAndFilename As String

Dim con As New OleDb.OleDbConnection

Dim ds As New DataSet

Dim da As OleDb.OleDbDataAdapter

Dim sql As String


 

Next in the Load event set a few.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;" ' MDB

    'dbProvider = "PROVIDER=Microsoft.Ace.OLEDB.12.0;" 'ACCDB

    dbSource = "Data Source="

    LoadData()

End Sub


 

Load the Data.

Sub LoadData()

    'Connect to db

    'You could store the db path in the Settings of the App.

    'dbPathAndFilename = My.Settings.dbPath

    dbPathAndFilename = "C:\Users\%USER%\Documents\db.mdb"

    con.ConnectionString = dbProvider & dbSource & dbPathAndFilename

    con.Open()

    sql = "SELECT * FROM table;"

    da = New OleDb.OleDbDataAdapter(sql, con)

    'Give it a name.

    da.Fill(ds, "TABLE")

    con.Close()

    'Populate the DataGridView

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

End Sub


 

Original

Start a NEW Conversation
 
Only students may post on this page. Click here for more information on how you can set up an account. If you are a student, please Log On first. Non-students may only post in the Visitor Forum.
 
Subscribe
Subscribe to Connect to Access DB
Get notifications when this page is updated
 
 
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 6/16/2026 6:32:33 PM. PLT: 0s
Keywords: connect, access, db, database, vb, vbnet, vb.net  Page Tag: FORUMADMIN  PermaLink  Connect to Access DB