|
-
Mar 24th, 2010, 01:52 PM
#1
Thread Starter
Lively Member
Displaying database info in Listbox
ok Code:
Private Sub DisplayList(ByVal CusRef As Integer)
Dim ConnectionString As String
Dim SQLString As String
Dim TitleString As String
Dim conn As System.Data.OleDb.OleDbConnection
Dim dr As System.Data.OleDb.OleDbDataReader
Dim cmd As System.Data.OleDb.OleDbCommand
ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;data "
ConnectionString += "Source=" & "Opticians.accdb "
conn = New System.Data.OleDb.OleDbConnection(ConnectionString)
SQLString = "SELECT * FROM SpecSalesTable" 'SELECTS ALL INFORMATION
Try ' FROM DATABASE
conn.Open()
If ConnectionState.Open Then
cmd = New System.Data.OleDb.OleDbCommand(SQLString, conn)
dr = cmd.ExecuteReader()
If dr.HasRows Then
FramesListBox.Items.Clear()
While dr.Read
If Not IsDBNull(dr.Item("CustomerID")) Then 'INSERTS INFORMATION INTO
TitleString = dr.Item("CustomerID") ' LISTBOX
FramesListBox.Items.Add(TitleString)
End If
End While
End If
dr.Close()
End If
Catch
MessageBox.Show("Error accessing database") 'IF ERROR ENCOUNTERED SHOWS MESSAGE
End Try
conn.Close()
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
-
Mar 24th, 2010, 01:56 PM
#2
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
-
Mar 24th, 2010, 01:58 PM
#3
Thread Starter
Lively Member
Re: Displaying database info in Listbox
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|