Monday, July 30, 2018

Fransiskus Sutris

VB.Net Tutorial Creating a Function Displaying Data From Table To Datagridview

The purpose of making this function is to facilitate and accelerate the making of the application, because every time you will display data from the table to the datagridview you simply call this function so there is no need to rewrite the long program code.

I hope you understand first how to create database and table in mysql.


  1. Create database with name: kampus_db and create table t_mahasiswa with structure below. please execute your sql script following:

  1. Add Mysql.Data.dll in Project Reference
  1. Add a Module and name it Module1.vb, then copy the following program code :

  1. Please add Windows Form and leave the name Form2.vb, drag the datagridview control into form2, add the Button to the form2 as shown below:
  1. Double Click on control Button 1, then copy the following program code on sub Button1_Click :

The full program code in form2.vb is as follows :

  1. Please change the Startup Form on the project properties to Form2. Then try press F5 to run the program. When executed and Button1 is clicked then student data from table t_mahasiswa will appear in datagridview:

  1. So every time you will display data from table to datagridview just call the showDataToDGV function.
showDataToDGV(sql As String, tabelName As String, dgv As DataGridView)
Explanation Function showDataToDGV :
ParameterDescription
sqlsql query to read data with prefixed commands select
tableNameselected table names
dgvcontrol name datagridview which will be used to display data

Read More