Eventually i want to load names from a database to textboxes which are created at runtime. Thought i'd try just getting names into a listbox first though as i'm new to using databases in vb and for some reason nothings getting added to the listbox
Heres the code iv'e got so far which isn't working, tried searching but can't find anything similiar using oleDb i'm guesing it's a old way of doing things or something?
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
ListBox1.Items.Clear()
Dim connection As New OleDbConnection("provider=Microsoft.jet.Oledb.4.0;data source=P:\Comp4 project\myDB.mdb")
Try
connection.Open()
Dim command As OleDbCommand = New OleDbCommand("SELECT Name FROM Component_Table WHERE Quantity<10")
Dim sdr As OleDbDataReader
sdr = command.ExecuteReader()
Dim i As Integer
i = 0
While sdr.Read()
ListBox1.Items.Add(sdr(i).ToString)
i = i + 1
End While
sdr.Close()
connection.Close()
Catch ex As Exception
End Try
End Sub