I have a textbox in which a user can enter a hotel name and then clicks the Search button. A list of hotels with given name should be displayed upon doing so. Whenever I enter a hotel name and click the button, nothing gets displayed. Below is my code, thank you for any advice:
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
尝试在查询中添加加号(+),并在百分号(%)之后添加单引号。
WHERE Hotel_Name Like '%'+" & SearchHotel & "+'%'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.