如果我在文本框中输入输入,我的listview会更新,但即使我的输入存在,也总是没有结果。
Private Sub searchRecord()
Dim dt As New DataTable
dt = ExecuteQuery("SELECT * FROM tblSupplier WHERE '" & cboSearch.Text
& "' LIKE '" & txtSearch.Text & "%'")
lvSupplier.Items.Clear()
If dt.Rows.Count > 0 Then
For ctr = 0 To dt.Rows.Count - 1
Dim item As New ListViewItem
item.Text = dt.Rows(ctr)("SuppID")
item.SubItems.Add(dt.Rows(ctr)("SuppName"))
item.SubItems.Add(dt.Rows(ctr)("SuppAddress"))
item.SubItems.Add(dt.Rows(ctr)("SuppConPerson"))
item.SubItems.Add(dt.Rows(ctr)("SuppConNumber"))
item.SubItems.Add(dt.Rows(ctr)("SuppEmail"))
lvSupplier.Items.Add(item)
Next
End If
End Sub
Dim dt As New DataTable
dt = ExecuteQuery("SELECT * FROM tblSupplier")
Try
If txtSearch.Text = "" Then
Call fillSupplier(dt, lvSupplier)
Else
Call searchRecord()
End If
Catch ex As Exception
MsgBox(ex.ToString)
End Try
答案 0 :(得分:2)
您的SQL语句应该是这样的......
"SELECT * FROM tblSupplier WHERE " & cboSearch.Text & " LIKE '%" & txtSearch.Text.Replace("'","''").Trim() & "%'"
这样,您就可以搜索任何字符或单词,无论它放在数据库中的原始单词或短语中。