B4J Question Mysql Select search

atiaust

Active Member
Licensed User
Longtime User
Hi All,

I am trying create a SELECT query on a Mysql database to find records that match the search text field.
ie txtSearch.Text ="B" and records in database "Brown" , "Britten" etc

Database "Persons", Table "table" and column "name"

Trying to get this to work.

cursor = Sql.ExecQuery2("SELECT * FROM table WHERE name LIKE ?",Array As String(txtSearch.text))

Can someone tell me if this looks correct?

Thanks
 

klaus

Expert
Licensed User
Longtime User
Your query will not work as you expect.
If you want only the names beginning with 'B' then you should use:
cursor = Sql.ExecQuery2("SELECT * FROM table WHERE name LIKE ?",Array As String(txtSearch.text & "%"))
LIKE 'B%' returns all names beginning with B
LIKE '%B%' returns all names containing B
LIKE '%B' returns all names ending with B
You may have a look HERE.
 
Upvote 0

atiaust

Active Member
Licensed User
Longtime User
Hi Klaus,

Thank you for your reply.

I was close but not quite there. Works properly now.

Thanks
 
Upvote 0
Top