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