c# MySQL like query not taking parameters

c#, mysql

Solution

You're currently putting your parameter within quotes, which means it's no longer being used as a parameter. I suspect you want:

string cmdText = "SELECT * FROM tblshareknowledge where title LIKE @myTitle";
cmd = new MySqlCommand(cmdText, con);
cmd.Parameters.AddWithValue("@myTitle", "%" + title + "%");

Problem

I am using a query to find keywords in a particular field, when i put the @parameter and then addparameter with value it does not work, however when i input the value directly, it works, anyone can help me pass value as parameter to my query please? below are my codes: This works and retrieves any record with the word "My" in its title. ``` string cmdText = "SELECT * FROM tblshareknowledge where title LIKE '%My%'"; cmd = new MySqlCommand(cmdText, con); //cmd.Parameters.AddWithValue("@myTitle", title); ``` This one does not work: ``` string cmdText = "SELECT * FROM tblshareknowledge where title LIKE '@myTitle'"; cmd = new MySqlCommand(cmdText, con); cmd.Parameters.AddWithValue("@myTitle", title); ```

Original source