-1

I've been stuck with this since this morning, I'm trying to search on the database table using LIKE statement but I'm getting trouble at where to put the % sign. I already tried different approach but It's not working.

At first I tried the

Dim cur As Cursor
cur = Main.SQL1.ExecQuery2("SELECT * from tbl_info WHERE info_name LIKE  '%?%' ",Array As String(searchString))

But that does not work then I also tried this

Dim cur As Cursor
cur = Main.SQL1.ExecQuery2("SELECT * from tbl_info WHERE info_name LIKE  '"+searchString+"' ",Array As String(searchString))

But I'm getting numberformat exception even though the searchString contains Strings.

keysl
  • 2,127
  • 1
  • 12
  • 16

1 Answers1

1

Your query needs to be like this:

cur = Main.SQL1.ExecQuery2("SELECT * from tbl_info WHERE info_name LIKE ?", "%" + Array As String(searchString)) + "%"

Now the bound parameter can be replaced and the necessary wildcards are added to it.
No need to worry about the string delimiters ('), since they will be added automatically as needed, during the binding process.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115