I´working on a C# desktop App and want to search in a MYSQL database all the records that match with a specific name in order to display this records into a datagridview but got the error when executing the query with the value: pablo

this is my query
sentencia = "select * from registro where nombreParticipante LIKE '%' + @valor + '%'";
nombre = valor.ToUpper();
cmd.Parameters.AddWithValue("@valor", nombre);
cmd.CommandText = sentencia;
could you tell me what is wrong with the code please
Try this code :
"select * from registro where nombreParticipante LIKE '% + @valor + %'";
The correct syntax of LIKE is :
WHERE 'STRING' LIKE '%OtherString%'
And what you did is:
WHERE 'STRING' LIKE '%'OtherString'%'
Format the string for your parameter rather than in the query:
sentencia = "select * from registro where nombreParticipante LIKE @valor";
nombre = valor.ToUpper();
cmd.Parameters.AddWithValue("@valor", "%" + nombre + "%");
cmd.CommandText = sentencia;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With