【发布时间】:2013-10-04 16:25:35
【问题描述】:
伙计们,我想在 vb 中构建一个高效的搜索工具,以从我存储了一些信息段落的 mysql 数据库中搜索数据。我希望搜索像谷歌一样返回多个结果,但在文本框中以相同概念的 2-3 段形式返回。此外,为了使搜索更有效,我想在选择中包含子字符串功能,即 % 符号询问。谁能告诉我如何实现这两个功能?这是我的基本搜索代码,它只将存储在表格中的单个段落返回到我的结果文本框中,我首先隐藏它,然后在结果出现时显示。
If TextBox1.Text = "" Then
MsgBox("Please Enter a Keyword")
Else
Dim conn As MySqlConnection
conn = New MySqlConnection
conn.ConnectionString = "Server=localhost;UserID=root;Password=admin674;Database=db1"
Dim myadapter As New MySqlDataAdapter
conn.Open()
Dim sqlquery = "select text from text where name like '" & TextBox1.Text & "'"
Dim mycommand As New MySqlCommand
mycommand.Connection = conn
mycommand.CommandText = sqlquery
myadapter.SelectCommand = mycommand
Dim mydata As MySqlDataReader
mydata = mycommand.ExecuteReader
If mydata.HasRows = 0 Then
MsgBox("Data Not Found")
TextBox1.Clear()
TextBox2.Clear()
Else
mydata.Read()
TextBox2.Text = mydata.Item("text")
TextBox2.Show()
End If
【问题讨论】:
-
你问如何在一个文本框中显示多个结果?这只是
txtResults.Text &= mydata.Item("text"),因为您循环遍历结果(似乎没有实现多个返回的循环)。关于子字符串和 %,我不遵循您想要的,抱歉 -
对于子字符串,我的意思是我必须输入确切的关键字才能从数据库中搜索,所以为了消除这个问题,我需要一个查询来搜索子字符串,这样用户就不必输入确切的数据库中存在的关键字
标签: vb.net