Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   Seminars   Templates   TechHelp   Fast Tips   Forums   Help   Contact   Join   Order   Logon  
 
Tips & Tricks

New Tips Added Weekly!
Click here to get on our Mailing List

   
 
VB.NET

Connect to Access DB

How to connect to an Access Database.

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"
		conAn.ConnectionString = dbProvider & dbSource & dbPathAndFilename
		 
		conAn.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
	

 

Alex Hedley (Avatar) By: Alex Hedley


Click here to sign up for more FREE tips

 

Check out these other pages that may be of interest to you:

 

 

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
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    Twitter

YouTube Channel    LinkedIn
Copyright 2023 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 3/31/2023 12:59:25 PM.