V
VB Novice Hendri
Guest
Hi
I am trying this tipe of code to populate a ListBox with Tabel names. Making a selektion in the ComboBox must then populate the ListBox with the names of Tabels in that selected DataBase. The top half of this code is mine, while the botom half is not and I dont understand it at all.
Private Sub CategoryComboBox_SelectedIndexChanged(sender As Object, e As EventArgs) Handles CategoryComboBox.SelectedIndexChanged
Dim DataBaseToUse As String = ""
Select Case CategoryComboBox.Text
Case Is = "Smaaklik Tuisgemaakte Drankies"
DataBaseToUse = "M:\My Documents\My Resepte\Drankies.accdb"
Case Is = "Voorgeregte & Ander Ligte Eetes"
DataBaseToUse = "M:\My Documents\My Resepte\Voorgeregte.accdb"
Case Is = "Hoofgeregte"
DataBaseToUse = "M:\My Documents\My Resepte\Hoofgeregte.accdb"
Case Is = "Watertand Nageregte & Poedings"
DataBaseToUse = "M:\My Documents\My Resepte\Nageregte.accdb"
Case Is = "Kraakvars Slaai Resepte"
DataBaseToUse = "M:\My Documents\My Resepte\Slaaie.accdb"
Case Is = "Souse & Marinades"
DataBaseToUse = "M:\My Documents\My Resepte\Souse.accdb"
Case Is = "Geurige Tuisgebak"
DataBaseToUse = "M:\My Documents\My Resepte\Gebak.accdb"
Case Is = "Gebottelde & Ingelegde Lekerneie"
DataBaseToUse = "M:\My Documents\My Resepte\Gebottelde.accdb"
Case Is = "Wenke & Boererate vir in en om die Huis"
DataBaseToUse = "M:\My Documents\My Resepte\Wenke.accdb"
End Select
'Populating TitleListBox
TitleListBox.DataSource = DataBaseToUse
Dim database = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "AccessDatabases", DataBaseToUse)
connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & database
Using cn As OleDbConnection = New OleDbConnection(connString)
cn.Open()
Dim dtNames As DataTable = cn.GetSchema("Tables", New String() {Nothing, Nothing, Nothing, "TABLE"})
TitleListBox.Items.Clear()
For Each row As DataRow In dtNames.Rows
Dim tablename As String = CStr(row(2))
TitleListBox.Items.Add(tablename)
Next
End Using
End Sub
Continue reading...
I am trying this tipe of code to populate a ListBox with Tabel names. Making a selektion in the ComboBox must then populate the ListBox with the names of Tabels in that selected DataBase. The top half of this code is mine, while the botom half is not and I dont understand it at all.
Private Sub CategoryComboBox_SelectedIndexChanged(sender As Object, e As EventArgs) Handles CategoryComboBox.SelectedIndexChanged
Dim DataBaseToUse As String = ""
Select Case CategoryComboBox.Text
Case Is = "Smaaklik Tuisgemaakte Drankies"
DataBaseToUse = "M:\My Documents\My Resepte\Drankies.accdb"
Case Is = "Voorgeregte & Ander Ligte Eetes"
DataBaseToUse = "M:\My Documents\My Resepte\Voorgeregte.accdb"
Case Is = "Hoofgeregte"
DataBaseToUse = "M:\My Documents\My Resepte\Hoofgeregte.accdb"
Case Is = "Watertand Nageregte & Poedings"
DataBaseToUse = "M:\My Documents\My Resepte\Nageregte.accdb"
Case Is = "Kraakvars Slaai Resepte"
DataBaseToUse = "M:\My Documents\My Resepte\Slaaie.accdb"
Case Is = "Souse & Marinades"
DataBaseToUse = "M:\My Documents\My Resepte\Souse.accdb"
Case Is = "Geurige Tuisgebak"
DataBaseToUse = "M:\My Documents\My Resepte\Gebak.accdb"
Case Is = "Gebottelde & Ingelegde Lekerneie"
DataBaseToUse = "M:\My Documents\My Resepte\Gebottelde.accdb"
Case Is = "Wenke & Boererate vir in en om die Huis"
DataBaseToUse = "M:\My Documents\My Resepte\Wenke.accdb"
End Select
'Populating TitleListBox
TitleListBox.DataSource = DataBaseToUse
Dim database = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "AccessDatabases", DataBaseToUse)
connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & database
Using cn As OleDbConnection = New OleDbConnection(connString)
cn.Open()
Dim dtNames As DataTable = cn.GetSchema("Tables", New String() {Nothing, Nothing, Nothing, "TABLE"})
TitleListBox.Items.Clear()
For Each row As DataRow In dtNames.Rows
Dim tablename As String = CStr(row(2))
TitleListBox.Items.Add(tablename)
Next
End Using
End Sub
Continue reading...