VB.NET Add Items to a ListView From MySQL Database with DataSet

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 :
  1. How to fill data from database into a DataGridView?
  2. How to Paging/Sorting in a DataGridView?

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 picture

Add Items to a ListView From MySQL Database with DataSet

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)

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

Next Recomended


Feel free to code it up and send us a pull request.

Hi everyone, let's me know how much this lesson can help your work. Please Subscribe and Follow Our Social Media 'kodeajaib[dot]com' to get Latest tutorials and will be send to your email everyday for free!, Just hit a comment if you have confused. Nice to meet you and Happy coding :) all ^^



Follow by E-Mail


Name

ADO.NET,3,Ajax,6,Android,9,AngularJS,4,ASP.NET,4,Blogger Tutorials,7,Bootstrap,7,C++,1,Codeigniter,2,Cplusplus,6,Crystal Report,6,CSharp,25,Ebook Java,2,FlyExam,1,FSharp,3,Game Development,2,Java,35,JDBC,2,Laravel,84,Lumen,2,MariaDB,2,Ms Access,3,MySQL,31,ODBC,6,OleDB,1,PHP,14,PHP Framework,5,PHP MYSQLI,9,PHP OOP,5,Python,8,Python 3,4,SQL Server,4,SQLite,4,Uncategorized,5,Vb 6,2,Vb.Net,89,Video,48,Vue Js,4,WPF,2,Yii,3,
ltr
item
KODE AJAIB: VB.NET Add Items to a ListView From MySQL Database with DataSet
VB.NET Add Items to a ListView From MySQL Database with DataSet
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?
https://4.bp.blogspot.com/-txlweHCyDFk/V5j9h7qUh0I/AAAAAAAACKU/LOWgn7R8Y20N057YeiYY8hJ4vZTWvu_hwCLcB/s320/fill-data-into-listview.jpg
https://4.bp.blogspot.com/-txlweHCyDFk/V5j9h7qUh0I/AAAAAAAACKU/LOWgn7R8Y20N057YeiYY8hJ4vZTWvu_hwCLcB/s72-c/fill-data-into-listview.jpg
KODE AJAIB
https://www.kodeajaib.com/2016/07/vbnet-add-items-to-listview-from-databases.html
https://www.kodeajaib.com/
https://www.kodeajaib.com/
https://www.kodeajaib.com/2016/07/vbnet-add-items-to-listview-from-databases.html
true
3214704946184383982
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy