I'm attempting to query an Access database using a search button from a textbox and insert the results into a listbox. Here's the code I have so far:
Dim con As New OleDbConnection(DBcon)
Try
lbresults.Items.Clear()
Dim dr As OleDbDataReader
Dim command As New OleDbCommand("Select I.InstName, S.StuName FROM Instructor I, Student S WHERE I.InstName Like '%" & txtsearch.Text & "%' and S.StuName like '%" & txtsearch.Text & "%'", con)
con.Open()
command.Connection = con
dr = command.ExecuteReader
While dr.Read()
lbresults.Items.Add(dr("InstName"))
lbresults.Items.Add(dr("StuName"))
End While
Catch ex As Exception
The problem I'm having is it's returning the both InstName and the StuName multiple times in the listbox. I'm guessing it's because I'm doing the items.add twice? I was trying to use "[oledbcommand variable name].parameters.addwithvalue" but I couldn't figure out how to do it with a "like" function.