Solved

Bind listBox control with sql data in vb.net windows Application

Posted on 2013-01-29
1
562 Views
Last Modified: 2013-02-07
How to Bind listBox control with sql data in vb.net windows Application?
0
Comment
Question by:mohgt
1 Comment
 
LVL 18

Accepted Solution

by:
John (Yiannis) Toutountzoglou earned 500 total points
ID: 38834146
Try this Example
Imports System.Data.SqlClient

 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      'Create Connection object
      Dim thisConnection As New SqlConnection(MyProjectConnectionString)

      ' Sql Query 
      Dim sql As String = _
         "SELECT FirstName, LastName FROM MyTable"

      ' Create Data Adapter
      Dim da As New SqlDataAdapter(sql, thisConnection)

      ' Fill Dataset and Create DataTable
      da.Fill(DataSet1, "MyTable")
      Dim dt As DataTable = DataSet1.Tables("MyTable")

      ListBox1.DataSource = dt
      ListBox1.DisplayMember = "Lastname"

End Sub

Open in new window

0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question