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.
The full program code in form2.vb is as follows :
I hope you understand first how to create database and table in mysql.
- Create database with name: kampus_db and create table t_mahasiswa with structure below. please execute your sql script following:
- Add Mysql.Data.dll in Project Reference
- Add a Module and name it Module1.vb, then copy the following program code :
- 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:
- 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 :
- 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:
- So every time you will display data from table to datagridview just call the showDataToDGV function.
Parameter | Description |
---|---|
sql | sql query to read data with prefixed commands select |
tableName | selected table names |
dgv | control name datagridview which will be used to display data |