How to display MS Access table on DataGridView VB.Net

Continuing my previous tutorial, here I want to show you how to display or populate MS Access table into a DataGridView under Visual Basic .NET. Its pretty easy to load and display MS Access table on our program/form.

Design the form

form 1

As you can see, I have two button Connect and Show Data. The Connect button is used to connect to the database and the other one is to display a table content to DataGridView.

The Code

First we need to create a module. This module will handle every connections to the database through OleDb connection. To add a module, go to Project | Add New Item. Select Module from the list and enter the name of the new module.

add module to 2015

The following code are typed inside a module called MyModuleConnect

Now back to the main form and we will add code for the Connect button. Connect button will attempt to open the connection to the database. tutorial 01

Now, Show Data button code:

Run the program tutorial 02

Thank you. Hope this is useful for anyone who wants to start learning Visual Basic 2015.


Leave a Reply

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