by Russ Green (2 Submissions)
Category: Miscellaneous
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Fri 22nd November 2002
Date Added: Mon 8th February 2021
Rating: (1 Votes)
Populates a list control (listbox, combobox, etc) from the contents of a database.
ByVal Database As String, ByVal DataTable As String, ByVal DataColumn As String) As Boolean
'connection stuff
Dim con As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Database)
Dim cm As New OleDb.OleDbCommand("SELECT * FROM" & " " & DataTable, con)
Dim dr As OleDb.OleDbDataReader
'empty ListControl first
ListControl.Items.Clear()
'read table and fill ListControl
Try
con.Open()
dr = cm.ExecuteReader(CommandBehavior.CloseConnection)
While dr.Read()
ListControl.Items.Add(dr(DataColumn))
End While
Catch ex As Exception
MessageBox.Show(ex.Source & ": " & ex.Message)
Finally
cm.Dispose()
cm = Nothing
con.Dispose()
con = Nothing
dr = Nothing
End Try
End Function
No comments have been posted about Populates a list control (listbox, combobox, etc) from the contents of a database.. Why not be the first to post a comment about Populates a list control (listbox, combobox, etc) from the contents of a database..