Store Database data into a ListBox : Database ListBox « Database ADO.net « VB.Net

Home
VB.Net
1.2D
2.Application
3.Class
4.Data Structure
5.Data Types
6.Database ADO.net
7.Development
8.Event
9.File Directory
10.Generics
11.GUI
12.Language Basics
13.LINQ
14.Network Remote
15.Security
16.Thread
17.Windows Presentation Foundation
18.Windows System
19.XML
20.XML LINQ
VB.Net Tutorial
VB.Net by API
VB.Net » Database ADO.net » Database ListBoxScreenshots 
Store Database data into a ListBox
Store Database data into a ListBox

 Imports System
 Imports System.Drawing
 Imports System.Collections
 Imports System.ComponentModel
 Imports System.Windows.Forms
 Imports System.Data
 Imports System.Data.SqlClient
 
Public Class MainClass

    Shared Sub Main(  )
        Application.Run(New ADOForm1() )
    End Sub

   
End Class

     Public Class ADOForm1
     Inherits System.Windows.Forms.Form

     Private components As System.ComponentModel.Container
     Private lbEmployees As System.Windows.Forms.ListBox

     Public Sub New(  )
         InitializeComponent(  )

         Dim connectionString As String ="server=(local)\SQLEXPRESS;" & _
          "integrated security=sspi;database=MyDatabase"


         Dim commandString As String = _
           "Select FirstName, LastName from Employee"

         Dim myDataAdapter As New SqlDataAdapter_
           commandString, connectionString)

         Dim myDataSet As New DataSet(  )

         myDataAdapter.Fill(myDataSet, "Employee")

         Dim myDataTable As DataTable = myDataSet.Tables(0)

         Dim tempRow As DataRow
         For Each tempRow In myDataTable.Rows
             lbEmployees.Items.Add((tempRow("FirstName"& _
               " (" & tempRow("LastName"")"))
         Next

     End Sub 'New

     Private Sub InitializeComponent(  )
         Me.components = New System.ComponentModel.Container(  )
         Me.lbEmployees = New System.Windows.Forms.ListBox(  )
         lbEmployees.Location = New System.Drawing.Point(4824)
         lbEmployees.Size = New System.Drawing.Size(368160)
         lbEmployees.TabIndex = 0
         Me.Text = "ADOFrm1"
         Me.AutoScaleBaseSize = New System.Drawing.Size(513)
         Me.ClientSize = New System.Drawing.Size(464273)
         Me.Controls.Add(lbEmployees)
     End Sub 'InitializeComponent

 End Class 'ADOForm1
           
       
Related examples in the same category
1.Read Access Data table and store data in ListBoxRead Access Data table and store data in ListBox
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.