So, I have a method that performs a parametrised LIKE query. The method takes in the search parameter/value in and then it is added to the command ready for the query.
It is not working. It should work, and when I code the value to search for directly into the SQL string, sans parametrisation, it does work! When I have it as a parameter is does not! Any ideas.
Here is some (fake, I have changed the names) example code.
myDataReader = SQLExecute("SELECT * FROM TableOfAwesomeness WHERE BestTVShow LIKE 'Arrested Development%'")
Would work. However
Function MethodOfReturningHorror(ByVal TVShow as String) as SqlDataReader
{
dim command as new SQLCommand
command.connection = sqlconnection
command.CommandText = "SELECT * FROM TableOfAwesomeness WHERE BestTVShow LIKE '@tvShow%'"
command.Parameters.Add("tvShow",TVShow)
return command.ExecuteReader()
}
I have missed out code unrelated to the question for the sake of laziness/conciseness. So ignore the return bit and and stuff, all that is important is that the data reader contains nothing, while It does in the first example. I am sure it's to do with the parametrisation of the LIKE clause .
Thanks!