Search code examples
mysqlsqlvb.netsql-likeclause

How to query using LIKE clause in mysql using vb.net comparing to a varied string input?


I've search and tried a lot of procedure but did not work. CREATE PROCEDURE did not work, SET @variable is not acceptable and a couple more codes. This is my last "query" code that still didn't work.

qry = "select * from employeefile where empfname LIKE '%''" + input + "''%'"

empfname is a name of an employee from table employeefile that possibly consists of three words. The input could be the first word, second word, third word or the entire words.

when i tried to input any word within the name, the program will still prompt, "no records found." when i tried to change the query into

qry = "select * from employeefile where empfname LIKE '%existingname%'"

and my input is "existingname", the program runs just as i want it to.

This code is one of those that i seached but still didn't work.

T-SQL and the WHERE LIKE %Parameter% clause

How to use like clause in MySQL 5.0 Statement

T-SQL and the WHERE LIKE %Parameter% clause

The problem here is when i use a variable... i probably get the wrong way of using it into query. Please help me. I am new here by the way.


Solution

  • i got the answer. it turns out that i just overdid the single quote. it must be written this way:

    qry = "select * from employeefile where empfname LIKE '%" + input + "%'"