ListView VB.NET tutorials : How to fill data from database into a listview, how to Populate a Listview with data from MySQL database use any Dataset?
VB.NET for Beginners : How to show data from database (MySQL Database) into a listview using Dataset with vb.net programming language? A listView can handle columns, items from any database using Dataset or dataTable. A Columns name in a ListView can configured using lv.Columns(0).Text functions.
Please Read :
After done, we will start create a code to connect with MySQL database and show all data columns and items into our ListView.
Source Code Add Items to a ListView From MySQL (Form1.vb)
Now you can try our simple project and let me know what happen after you press "F5" key, if you're still confused, just watch video tutorial below.
See you next lessons.
Please Read :
Populate a ListView from MySQL Database
Now we can try to make a new project using ListView Component Visual studio, please create a project and rename it with "VBnetListView", at the Form1.vb add one ListView Component and just design it look like this pictureAfter done, we will start create a code to connect with MySQL database and show all data columns and items into our ListView.
Source Code Add Items to a ListView From MySQL (Form1.vb)
Imports System.Data.Odbc
' we will create connection using ODBC namespaces
Public Class Form1
Dim connect As OdbcConnection
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' configure the listview
ListView1.View = View.Details
ListView1.GridLines = True
' create a connection to our database (i'm use MySQL database)
connect = New OdbcConnection("DSN=k13new;MultipleActiveResultSets=True")
' open connection
connect.Open()
Dim cmd As New OdbcCommand("SELECT * FROM biodata", connect)
Dim da As New OdbcDataAdapter(cmd) ' we will use dataadapter
Dim ds As New DataSet
da.Fill(ds, "biodata")
' now we will add the columns in listview
For i As Integer = 0 To ds.Tables(0).Columns.Count - 1
ListView1.Columns.Add(ds.Tables(0).Columns(i).ColumnName.ToString())
Next
' rename headers columns
ListView1.Columns(0).Text = "Id Siswa" ' header name of columns 0
ListView1.Columns(1).Text = "Nama Siswa"
ListView1.Columns(2).Text = "Nis"
ListView1.Columns(3).Text = "Nisn"
ListView1.Columns(4).Text = "Jenis Kelamin"
ListView1.Columns(5).Text = "Tempat Lahir"
ListView1.Columns(6).Text = "Tanggal Lahir"
ListView1.Columns(7).Text = "Agama"
ListView1.Columns(8).Text = "Alamat"
ListView1.Columns(9).Text = "Sekolah Asal"
ListView1.Columns(10).Text = "Alamat Sekolah"
ListView1.Columns(11).Text = "Thn Ijazah"
ListView1.Columns(12).Text = "No Ijazah"
ListView1.Columns(13).Text = "Diterima"
ListView1.Columns(14).Text = "Tgl Diterima"
ListView1.Columns(15).Text = "Nama Ayah"
ListView1.Columns(16).Text = "Nama Ibu"
ListView1.Columns(17).Text = "ALamat Ortu"
ListView1.Columns(18).Text = "Telp"
ListView1.Columns(19).Text = "Pekerjaan"
ListView1.Columns(20).Text = "Status"
' now add items in listview
Dim itemcol(100) As String
For i As Integer = 0 To ds.Tables(0).Rows.Count - 1
For j As Integer = 0 To ds.Tables(0).Columns.Count - 1
itemcol(j) = ds.Tables(0).Rows(i)(j).ToString()
Next
Dim lvi As New ListViewItem(itemcol)
ListView1.Items.Add(lvi)
Next
End Sub
End Class
Now you can try our simple project and let me know what happen after you press "F5" key, if you're still confused, just watch video tutorial below.
Video tutorial Add Items to a ListView
See you next lessons.
COMMENTS