--> Skip to main content
Pelajar Koding

follow us

Vb.Net Mysql: Displaying Data On Datagridview

This is a serial panduan of VB.NET and MySQL, So make sure you understand the previous article first. Read also:  Connecting VB.NET to MySQL Database using MySQL Connector Next, we'll try to bind data from a database table to DataGridView. I have an example table named kategori. Query: Table values: For UI design, add DataGridView into a form then name it grdData. Type code as below: Imports MySql.Data.MySqlClient Imports System.Data Public Class Form1     Dim conn As MySqlConnection     Dim myCommand As New MySqlCommand     Dim myAdapter As New MySqlDataAdapter     Dim myData As New DataTable     Dim SQL As String     Private Sub Form1_Load( ByVal sender As System.Object, _     ByVal e As System.EventArgs) Handles MyBase .Load         conn = New MySqlConnection()         conn.ConnectionString = "server=localhost;user id=root;" & _                                 "password=;database=latihan"         Try             conn.Open()             SQL = "Select kodekategori, namakategori From klasifikasi"             myCommand.Connection = conn             myCommand.CommandText = SQL             myAdapter.SelectCommand = myCommand             myAdapter.Fill(myData)             grdData.DataSource = myData             conn.Close()         Catch myerror As MySqlException             MessageBox.Show( "Error: " & myerror.Message)         Finally             conn.Dispose()         End Try     End Sub End Class Try to run/debug application. Data will be displayed on datagridview. See also the video: Related topic: To support you in understanding this topic, please read also these articles: How to connect VB.NET to MySQL database How to binding MySQL data to DataGridView How to binding MySQL data to ComboBox List I divide this topic into 4 parts. Make sure you have read the previous article. How to Create, Read, Update, Delete (CRUD) - Part 1 How to Create, Read, Update, Delete (CRUD) - Part 2 How to Create, Read, Update, Delete (CRUD) - Part 3 How to Create, Read, Update, Delete (CRUD) - Part 4
Sumber http://rani-irsan.blogspot.com

You Might Also Like:

Comment Policy: Silahkan tuliskan komentar Anda yang sesuai dengan topik postingan halaman ini. Komentar yang berisi tautan tidak akan ditampilkan sebelum disetujui.
Buka Komentar