D
dennist
I finally figured out what others were telling me and was
able to fill as list box with the following code:
Imports System.Data
Imports System.Data.OleDb
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form
Designer.
InitializeComponent()
'Add any initialization after the
InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component
list.
Protected Overloads Overrides Sub Dispose(ByVal
disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the
Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents lstCustomers As
System.Windows.Forms.ListBox
<System.Diagnostics.DebuggerStepThrough()> Private
Sub InitializeComponent()
Me.lstCustomers = New System.Windows.Forms.ListBox
Me.SuspendLayout()
'
'lstCustomers
'
Me.lstCustomers.Location = New
System.Drawing.Point(8, 16)
Me.lstCustomers.Name = "lstCustomers"
Me.lstCustomers.Size = New System.Drawing.Size
(120, 147)
Me.lstCustomers.TabIndex = 0
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5,
13)
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Controls.Add(Me.lstCustomers)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
Dim strConn, strSQL As String
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=H:\Program Files\Microsoft Office\Office10
\Samples\Northwind.mdb;" ' & "Admin" & ""
strSQL = "SELECT CustomerID, CompanyName FROM
Customers"
Dim cn As New OleDbConnection(strConn)
cn.Open()
Dim cmd As New OleDbCommand(strSQL, cn)
Dim rdr As OleDbDataReader = cmd.ExecuteReader()
While rdr.Read()
'lstCustomers.Items.Add(rdr(1))
'MsgBox(rdr("CustomerID") & " - " & rdr
("CompanyName"))
'Console.WriteLine(rdr("CustomerID") & " - "
& rdr("CompanyName"))
End While
rdr.Close()
cn.Close()
End Sub
End Class
The problem remaining is how do I get rdr(0) into the
valuemember. This would really make me feel I'm getting
somewhere.
dennist
able to fill as list box with the following code:
Imports System.Data
Imports System.Data.OleDb
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form
Designer.
InitializeComponent()
'Add any initialization after the
InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component
list.
Protected Overloads Overrides Sub Dispose(ByVal
disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the
Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents lstCustomers As
System.Windows.Forms.ListBox
<System.Diagnostics.DebuggerStepThrough()> Private
Sub InitializeComponent()
Me.lstCustomers = New System.Windows.Forms.ListBox
Me.SuspendLayout()
'
'lstCustomers
'
Me.lstCustomers.Location = New
System.Drawing.Point(8, 16)
Me.lstCustomers.Name = "lstCustomers"
Me.lstCustomers.Size = New System.Drawing.Size
(120, 147)
Me.lstCustomers.TabIndex = 0
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5,
13)
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Controls.Add(Me.lstCustomers)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
Dim strConn, strSQL As String
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=H:\Program Files\Microsoft Office\Office10
\Samples\Northwind.mdb;" ' & "Admin" & ""
strSQL = "SELECT CustomerID, CompanyName FROM
Customers"
Dim cn As New OleDbConnection(strConn)
cn.Open()
Dim cmd As New OleDbCommand(strSQL, cn)
Dim rdr As OleDbDataReader = cmd.ExecuteReader()
While rdr.Read()
'lstCustomers.Items.Add(rdr(1))
'MsgBox(rdr("CustomerID") & " - " & rdr
("CompanyName"))
'Console.WriteLine(rdr("CustomerID") & " - "
& rdr("CompanyName"))
End While
rdr.Close()
cn.Close()
End Sub
End Class
The problem remaining is how do I get rdr(0) into the
valuemember. This would really make me feel I'm getting
somewhere.
dennist