In this tutorial, we will show you how to list all the tables in Microsoft Access using VB.NET. The idea is to list all the tables in listbox. See our example below. When the Show tables button is pressed, the program will add all the tables found on the database and add them into the ListBox. You can modify the code to suit your needs. You can freely use this code for your commercial work as well.
Here is the code:
Sub BtnshowtableClick(sender As Object, e As EventArgs)
Dim daftartabel As Data.DataTable = Nothing
Dim koneksi As System.Data.OleDb.OleDbConnection = New System.Data.OleDb.OleDbConnection()
koneksi.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\\drilling_fe.mdb"
Dim restrictions() As String = New String(3) {}
restrictions(3) = "Table"
koneksi.Open
daftartabel = koneksi.GetSchema("Tables",restrictions)
koneksi.Close
Dim i As Integer
For i = 0 To daftartabel.Rows.Count - 1 Step i + 1
listBox1.Items.Add(daftartabel.Rows(i)(2).ToString)
Next
End Sub