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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top