Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB Databases Basics
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
VB Databases Basics Beginning-level VB coding questions specific to using VB with databases. Issues not specific to database use will be redirected to other forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB Databases Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Closed Thread
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 21st, 2004, 07:27 PM
Authorized User
Join Date: Apr 2004
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default populating a list box using a DataReader

I'm hoping some very kind person can help me stop pulling my hair out. I've changed my approach to populating a list box by using a DataReader.

It displays the first match briefly then displays "Authenticate_User.MatchingRecord" for each instance of a match.

Authenticate_User is the name of the Program. MatchingRecord is a class.

I'm ready to give up. I've posted the code if you have time, I would buy you a big dinner.

The Public Class Works. I just included it in case you need it.
Public Class MatchingRecord
    Private cAccountName As String
    Public ReadOnly Property AccountName() As String
            Return cAccountName
        End Get
    End Property
    Private cAccountId As String
    Public ReadOnly Property AccountId() As String
            Return cAccountId
        End Get
    End Property
    Public Sub New(ByVal name As String, ByVal id As Integer)
        cAccountName = name
        cAccountId = id
    End Sub
End Class - This works

Private Sub txtSearch_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSearch.TextChanged
   Dim SQLStmt As String
   Dim DisplayedInList As Integer
   Dim Cnxn As New OleDbConnection( _
   "Provider=Microsoft.Jet.OLEDB.4.0;" _
   & "Data Source=CommonAlgorithms.mdb")
   If Cnxn.State <> ConnectionState.Open Then
            MsgBox("Unable to connect to the database...",
    End If (My SQL statement Works)
        SQLStmt = String.Format( _
           "SELECT (LastName + ', ' + FirstName) as AccountName, Id from Accounts WHERE LastName like '{0}%' ORDER BY LastName, FirstName", _
        'Debug.Write("SQLStmt=" & SQLStmt)
        Dim cmdSearch As New OleDbCommand(SQLStmt, Cnxn)
        Dim Matches As OleDbDataReader = cmdSearch.ExecuteReader

     Dim MatchingRecords As New ArrayList
     DisplayedInList = 0
     lbMatches.DisplayMember = "AccountName"
     lbMatches.ValueMember = "AcctId"
                MatchingRecords.Add(New MatchingRecord(Matches.Item
                ("AccountName"), Matches.Item("AcctId")))
                DisplayedInList += 1
            Loop Until (DisplayedInList > 50) Or Not Matches.Read

            lbMatches.DataSource = MatchingRecords
        End If
    End Sub

Thank you.

Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Populating a list box VBAbeginner Access VBA 1 April 8th, 2008 09:24 AM
multi-column list box values moved to 2nd list box sbmvr Access VBA 1 May 14th, 2007 01:58 PM
Binding a DataReader To A List Box testsubject ADO.NET 3 December 21st, 2005 06:41 AM
populating textboxes using list/Menu rylemer Javascript 0 November 23rd, 2005 10:05 PM
populating a box sporkman43 Classic ASP Basics 0 August 18th, 2003 02:04 PM

All times are GMT -4. The time now is 04:56 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.