Im trying to search a string from a textbox and display only the columns with that string inside them but it doesn't seem work well.
Database db = new Database();
MySqlCommand command = new MySqlCommand("SELECT * FROM `students`
LIKE
@studentEnrollment%'", db.GetConnection());
MySqlParameter nameParameter = command.CreateParameter();
command.Parameters.Add("@studentEnrollment", MySqlDbType.VarChar).Value = student_search_input;
MySqlDataAdapter adapter = new MySqlDataAdapter(command);
DataSet dataset = new DataSet();
adapter.Fill(dataset);
dataGridView1.DataSource = dataset.Tables[0];
I found a sketchy solution that worked for me. I just added +'%'
command.Parameters.Add("@studentEnrollment", MySqlDbType.String).Value =
student_search_input.Text+'%';
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.