我有一个文本框,用户可以在其中输入酒店名称,然后单击“搜索”按钮。这样做时,应显示具有指定名称的酒店列表。每当我输入酒店名称并单击按钮时,都不会显示任何内容。以下是我的代码,谢谢您的任何建议:
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim RegDataConn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; data source=" & Server.MapPath("App_Data/1202389.mdb"))
Dim SearchHotel As String = TBSearch.Text
Dim cmd As OleDbCommand = New OleDbCommand("SELECT Hotel.Hotel_Name, Hotel.Hotel_Location FROM Hotel WHERE Hotel_Name Like '%" & SearchHotel & "%' ", RegDataConn)
RegDataConn.Open()
Dim myDA As OleDbDataAdapter = New OleDbDataAdapter(cmd)
Dim myDataSet As DataSet = New DataSet()
myDA.Fill(myDataSet, "Table")
GridView1.DataSource = myDataSet.Tables("Table").DefaultView
End Sub
答案 0 :(得分:-2)
尝试在查询中添加加号(+) 并在百分号(%)后添加单引号。
WHERE Hotel_Name Like '%'+" & SearchHotel & "+'%'