伙计们,我想在 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