VB.NET Populate ComboBox From SQL Server Database

VB.NET - How To Fill ComboBox From SqlServer DataBase Using Visual Basic .Net

                                                                                                                         

In This VB.NET Tutorial We Will See How To Link ComboBox With Microsoft SQL DataBase Values Using Visual Basic .NET Programming Language.


Project Source Code:


Imports System.Data.SqlClient

Public Class vbnet_combobx_values_from_sql

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

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

        Dim command As New SqlCommand("select * from Users", connection)

        Dim adapter As New SqlDataAdapter(command)

        Dim table As New DataTable()

        adapter.Fill(table)

        ComboBox1.DataSource = table

        ComboBox1.DisplayMember = "Fname"
        ComboBox1.ValueMember = "Id"

    End Sub
End Class


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

vb.net populate combobox from sql server database







Share this

Related Posts

Previous
Next Post »