Filling TextBoxes with Data.

  • Thread starter Thread starter VB Novice Hendri
  • Start date Start date
V

VB Novice Hendri

Guest
I am using this code, it seems to work fine for one problem.

The problem ocurs with the TitleListBox_SelectedIndexChanged when the TextBoxes is sepose to be filled.

Private Sub CategoryComboBox_SelectedIndexChanged(sender As Object, e As EventArgs) Handles CategoryComboBox.SelectedIndexChanged

'The ComboBox contain an unbound list of witch the user can make a selection.
'The selection made is then matched with a corospondeg DataBase via this Select Case code block.

TitleListBox.Items.Clear()

Select Case CategoryComboBox.Text
Case Is = "Smaaklik Tuisgemaakte Drankies"
ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=M:\My Documents\My Resepte\Drankies.accdb"
TitleListBox.Items.Add("Koue Drankies")
TitleListBox.Items.Add("Melk Drankies")
TitleListBox.Items.Add("Warm Drankies")

Case Is = "Voorgeregte & Ander Ligte Eetes"
ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=M:\My Documents\My Resepte\Voorgeregte.accdb"
ActiveTabel = "VoorgeregteLigteEetes"
Call ShowRecipeNames()

Case Is = "Hoofgeregte"
ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=M:\My Documents\My Resepte\Hoofgeregte.accdb"


Case Is = "Watertand Nageregte & Poedings"
ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=M:\My Documents\My Resepte\Nageregte.accdb"


Case Is = "Kraakvars Slaai Resepte"
ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=M:\My Documents\My Resepte\Slaaie.accdb"
ActiveTabel = "SlaaiResepte"
Call ShowRecipeNames()

Case Is = "Souse & Marinades"
ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=M:\My Documents\My Resepte\Souse.accdb"


Case Is = "Geurige Tuisgebak"
ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=M:\My Documents\My Resepte\Gebak.accdb"


Case Is = "Gebottelde & Ingelegde Lekerneie"
ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=M:\My Documents\My Resepte\Gebottelde.accdb"


Case Is = "Wenke & Boererate vir in en om die Huis"
ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=M:\My Documents\My Resepte\Wenke.accdb"


End Select

End Sub

Sub ShowRecipeNames()
Try
Using myConn As OleDbConnection = New OleDbConnection(ConnectionString)
myConn.Open()
Dim dtNames As DataTable = myConn.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
Catch ex As Exception
MessageBox.Show(ex.Message, "Problem Detected", MessageBoxButtons.OK, MessageBoxIcon.[Error])
End Try
End Sub


Private Sub TitleListBox_SelectedIndexChanged(sender As Object, e As EventArgs) Handles TitleListBox.SelectedIndexChanged

Dim tableName As String = TitleListBox.SelectedItem.ToString()

Using myConn As OleDbConnection = New OleDbConnection(ConnectionString)
myConn.Open()
Dim cmdText As String = ActiveTabel.ToString

Using cmd As OleDbCommand = New OleDbCommand(cmdText, myConn)
Dim reader = cmd.ExecuteReader()

While reader.Read()
Form1.TextBox1.Text = reader("ID").ToString()
Form1.TextBox2.Text = reader("RecipeName").ToString()
Form1.TextBox3.Text = reader("Comment").ToString()
Form1.TextBox4.Text = reader("Delivery").ToString()
Form1.TextBox5.Text = reader("Con1").ToString()
Form1.TextBox6.Text = reader("Con2").ToString()
Form1.TextBox7.Text = reader("Con3").ToString()
Form1.TextBox8.Text = reader("Con4").ToString()
Form1.TextBox9.Text = reader("Con5").ToString()
Form1.TextBox10.Text = reader("Con6").ToString()
Form1.TextBox11.Text = reader("Con7").ToString()
Form1.TextBox12.Text = reader("Con8").ToString()
Form1.TextBox13.Text = reader("Con9").ToString()
Form1.TextBox14.Text = reader("Con10").ToString()
Form1.TextBox15.Text = reader("Con11").ToString()
Form1.TextBox16.Text = reader("Con12").ToString()
Form1.TextBox17.Text = reader("Con13").ToString()
Form1.TextBox18.Text = reader("Con14").ToString()
Form1.TextBox19.Text = reader("Con15").ToString()
Form1.TextBox20.Text = reader("Con16").ToString()
End While
End Using
End Using
End Sub
1543027.jpg

Continue reading...
 

Similar threads

V
Replies
0
Views
110
VB Novice Hendri
V
V
Replies
0
Views
141
VB Novice Hendri
V
V
Replies
0
Views
99
VB Novice Hendri
V
V
Replies
0
Views
92
VB Novice Hendri
V
Back
Top