Results 1 to 3 of 3

Thread: Displaying database info in Listbox

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Location
    Ireland
    Posts
    85

    Displaying database info in Listbox

    ok Code:
    1. Private Sub DisplayList(ByVal CusRef As Integer)
    2.         Dim ConnectionString As String
    3.         Dim SQLString As String
    4.         Dim TitleString As String
    5.         Dim conn As System.Data.OleDb.OleDbConnection
    6.         Dim dr As System.Data.OleDb.OleDbDataReader
    7.         Dim cmd As System.Data.OleDb.OleDbCommand
    8.         ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;data "
    9.         ConnectionString += "Source=" & "Opticians.accdb "
    10.         conn = New System.Data.OleDb.OleDbConnection(ConnectionString)
    11.         SQLString = "SELECT * FROM SpecSalesTable" 'SELECTS ALL INFORMATION
    12.         Try                                     '    FROM DATABASE
    13.             conn.Open()
    14.             If ConnectionState.Open Then
    15.                 cmd = New System.Data.OleDb.OleDbCommand(SQLString, conn)
    16.                 dr = cmd.ExecuteReader()
    17.                 If dr.HasRows Then
    18.                     FramesListBox.Items.Clear()
    19.                     While dr.Read
    20.                         If Not IsDBNull(dr.Item("CustomerID")) Then  'INSERTS INFORMATION INTO
    21.                             TitleString = dr.Item("CustomerID")      '       LISTBOX
    22.                             FramesListBox.Items.Add(TitleString)
    23.                         End If
    24.                        
    25.                     End While
    26.                 End If
    27.                 dr.Close()
    28.             End If
    29.         Catch
    30.             MessageBox.Show("Error accessing database")     'IF ERROR ENCOUNTERED SHOWS MESSAGE
    31.         End Try
    32.         conn.Close()
    33.     End Sub


    So that works, but how do I display multiple things, CustomerID & CustomerName on the same line?

    I can't get it going, it only puts my CustomerName under the ID

  2. #2
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: Displaying database info in Listbox

    The listbox text line can contain only 1 thing. If you need to display more info then that you will need to do 1 of these things:

    1. Use a Listview instead
    2. When you query the db concatenate the field you want to see into on common result field.
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Location
    Ireland
    Posts
    85

    Re: Displaying database info in Listbox

    Ok thanks!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width