VB.Net/Database ADO.net/Database ListBox
Версия от 16:40, 26 мая 2010; (обсуждение)
Read Access Data table and store data in ListBox
Imports System
Imports System.Drawing
Imports System.Collections
Imports System.ruponentModel
Imports System.Windows.Forms
Imports System.Data
Imports System.Data.OleDb
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.ruponentModel.Container
Private lbEmployees As System.Windows.Forms.ListBox
Public Sub New( )
InitializeComponent( )
Dim connectionString As String = _
"provider=Microsoft.JET.OLEDB.4.0; " & _
"data source = Employee.mdb"
Dim commandString As String = _
"Select FirstName, LastName from Employee"
Dim myDataAdapter As New OleDbDataAdapter( _
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.ruponents = New System.ruponentModel.Container( )
Me.lbEmployees = New System.Windows.Forms.ListBox( )
lbEmployees.Location = New System.Drawing.Point(48, 24)
lbEmployees.Size = New System.Drawing.Size(368, 160)
lbEmployees.TabIndex = 0
Me.Text = "ADOFrm1"
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(464, 273)
Me.Controls.Add(lbEmployees)
End Sub
End Class
<A href="http://www.vbex.ru/Code/VBDownload/Employee.zip">Employee.zip( 7 k)</a>
Store Database data into a ListBox
Imports System
Imports System.Drawing
Imports System.Collections
Imports System.ruponentModel
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.ruponentModel.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.ruponents = New System.ruponentModel.Container( )
Me.lbEmployees = New System.Windows.Forms.ListBox( )
lbEmployees.Location = New System.Drawing.Point(48, 24)
lbEmployees.Size = New System.Drawing.Size(368, 160)
lbEmployees.TabIndex = 0
Me.Text = "ADOFrm1"
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(464, 273)
Me.Controls.Add(lbEmployees)
End Sub "InitializeComponent
End Class "ADOForm1