Populate ListBox From Database In Vb.Net

VB.NET - How To Fill ListBox From SQL Server Using Visual Basic .Net

vb.net listbox and sql server


In This VB.NET Tutorial We Will See How To Display Database Data Into Listbox Using Microsoft SQL DataBase And Visual Basic .NET Programming Language.


Project Source Code:

Imports System.Data.SqlClient

Public Class VBNET_ListBox_Items_From_SQL

    Dim connection As New SqlConnection("Server= SAMSNG-PC; Database = TestDB; Integrated Security = true")

    Private Sub VBNET_ListBox_Items_From_SQL_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        Dim command As New SqlCommand("select * from Users")
        command.Connection = connection

        Dim adapter As New SqlDataAdapter(command)
        Dim table As New DataTable()

        adapter.Fill(table)

        ListBox1.DataSource = table

        ListBox1.DisplayMember = "age"
        ListBox1.ValueMember = "Id"


    End Sub
End Class

///////////////OUTPUT:

vb.net listbox and database








Share this

Related Posts

Previous
Next Post »