【发布时间】:2013-01-08 03:35:21
【问题描述】:
我正在尝试使用文本框中的搜索按钮查询 Access 数据库并将结果插入到列表框中。这是我到目前为止的代码:
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
我遇到的问题是它在列表框中多次返回 InstName 和 StuName。我猜这是因为我正在做 items.add 两次?我试图使用“[oledbcommand 变量名].parameters.addwithvalue”,但我不知道如何使用“like”函数。
【问题讨论】:
标签: sql vb.net visual-studio-2010