The SQL that is used in C# has some particularities, for you to make a query using LIKE
, you should be aware of some things..
- If the value won’t be
null
or empty ""
, Empty
Be aware also in NEVER CONCATENATE, query strings. That is @Angelo’s answer, you may suffer from sql injection attacks. Whatever this is conversation 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 comparing with LIKE, primary key values, there is no why, nor with the CPF field, as the values will NEVER be approximated either they are or they are not!!
Create a connection class.
I don’t know if you did, but since your question is simple, it’s worth a few more tips! ;D
Valeuu!
The correct tag would not be [tag:sql]?
– ptkato