MySqlCommand command = new MySqlCommand("
select *
from singlecustomer
where name like concat ('%',@search,'%')
or code like concat ('%',@search,'%')
or id like concat ('%',@search,'%')", con);
command.Parameters.Add(new MySqlParameter("@search", "%"+sc.sc_SearchBox.Text+"%"));
MySqlDataAdapter adapter = new MySqlDataAdapter();
adapter.SelectCommand = command;
DataTable dt = new DataTable();
adapter.Fill(dt);
sc.dgClientLog.DataSource = dt;
this is the method that verify if the search is successful or not.
SearchClientDataGrid(sc);
if (sc.dgClientLog.Rows.Count == 0)
{
sc.NoItemFoundLabel.Visible = true;
sc.NoItemFoundLabel.BringToFront();
return;
}
else
{
sc.NoItemFoundLabel.Visible = false;
}
It works but whenever I search starting with the character "%" for Example: %David, it still work, is there a way to remove %? I'm recently learning MySql Parameter to avoid Sql Injection. It just ticks me off that % actually work instead of returning no found.
sc.sc_SearchBox.Text.Trim('%')