- Home
·
- Miscellaneous
·
- Populates a list control (listbox, combobox, etc) from the contents of a database.
Populates a list control (listbox, combobox, etc) from the contents of a database.
Populates a list control (listbox, combobox, etc) from the contents of a database.
Rate Populates a list control (listbox, combobox, etc) from the contents of a database.
(2(2 Vote))
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
Populates a list control (listbox, combobox, etc) from the contents of a database. Comments
No comments yet — be the first to post one!
Post a Comment