I'm trying to creat a search procedure that will search table game and return all rows where the title, description, platform, and gameid are LIKE parameter searchtext. This parameter is coming from many different pages as a Session("searchtext"), and I'm using a UserControl to send the Session, all pages in the site have the search UserControl.
In the searchresult.aspx page I have the following code (mysqlcommand cmdSearch, mysqldataadapter - daSearch, and mysqlconnection - cnn are in the design page):
Dim dsList As New DataSet
cmdSearch.Parameters("searchtext").Value = Session("searchtext")
If Not Page.IsPostBack() Then
lblRecordCount.Text = CStr(dsList.Tables(0).Rows.Count)
dsList = Nothing
dsList = New DataSet
daSearch.Fill(dsList, CInt(lblCurrIndex.Text), CInt(lblPageSize.Text), "game")
dlGames.DataSource = dsList.Tables(0).DefaultView
dlGames.DataKeyField = "gameid"
This is my statement (cmdSearch):
WHERE (title like '%' +:searchtext+ '%' or description like '%' +:searchtext+ '%' or platform like '%' +:searchtext+ '%' or gameid like '%' +:searchtext+ '%')
ORDER BY title
I'm not sure what I am doing wrong here. This statement is returning all games in the game table. I tried '%gamename%' and it worked fine, I'm assuming I need the single quotes again with the parameter because when I tried without the single qotes it didn't work. This is almost the same command as the one I have for the ShowAllGames command, the only difference is that I added the parameter for the search.