Parameters and LIKE

  • Thread starter Thread starter Jon
  • Start date Start date
J

Jon

I want to do the following, but I can't seem to get it right. It never
returns any data, even though rows do match. What's the correct way to use
LIKE with parameters?

ie, the following is not working for me:
strSQL = "SELECT * FROM Table WHERE Description LIKE '%@Descr%'"

I then go and do my parameter as usual, but it's not working.
 
Jon,

Here is some code that uses LIKE with a parameter:

Dim cmd As New OleDb.OleDbCommand()

cmd.CommandText = "Select ID, LastName + ', ' + FirstName As Customer From
Customers Where City Like ?"
cmd.Parameters.Add("@City", OleDb.OleDbType.VarChar)
cmd.Parameters("@City").Value = "%vill%"

Kerry Moorman
 
Back
Top