Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2013-01-29
1
Medium Priority
?
572 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 1500 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to shrink a transaction log file down to a reasonable size.

876 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