The SQL that is used in C # has some peculiarities, for you to make a query using LIKE
, you should be aware of some things ..
- Whether the value will not be
null
or empty ""
, Empty
Also be aware of NEVER CONCAT , the query strings. In other words, the response from @Angelo, can suffer with sql injection attacks. Whatever this is talk to another question ...
My answer to your problem ..
using(MySqlCommand cmd = new MySqlCommand(@"SELECT passe_os_campos_relevantes_para_voce_aqui FROM aluno WHERE ((idaluno = @id) OR (nomealuno LIKE '%' @nomealuno '%') OR (cpf = @cpf))"), new MySqlConnection("passe_sua_string_de_conexao")){
cmd.Parameters.AddWithValue("@id", id);
cmd.Parameters.AddWithValue("@nomealuno", nome);
cmd.Parameters.AddWithValue("@cpf", cpf);
}
I recommend never compare with LIKE, primary key values, there is no why, and neither with the CPF field, because the values will NEVER be approximated or are they or are they !!
Create a connection class.
I do not know if you did, but since your question is simple, it's worth a few more tips! ; D
Thanks!