I am currently working on my project and the problem that I've been facing for a while is when you are searching a data in database there's a slow down in performance and there's a unresponsiveness.
I've already created a thread but it still giving me a headache
//to start the thread when textbox has change
private void textBox1_TextChanged(object sender, EventArgs e)
{
ThreadStart thread2Start = new ThreadStart(searchMyData);
Thread t2 = new Thread(thread2Start);
t2.Start();
}
public void searchMyData()
{
if (radGridView1.InvokeRequired)
{
radGridView1.Invoke(new Action(() =>
{
MySqlConnection connection = new MySqlConnection(MyConnectionString);
MySqlCommand cmd;
connection.Open();
try
{
if(!(textBox1.Text=="Search Students"))
{
cmd = connection.CreateCommand();
cmd.CommandText = "SELECT * from studenttable where studname like'" + textBox1.Text + "%' OR studnum like'" + textBox1.Text + "%' OR studcourse like'" + textBox1.Text + "%' OR studemail like'" + textBox1.Text + "%' OR studsec like'" + textBox1.Text + "%' OR studgender like'" + textBox1.Text + "%' ";
MySqlDataAdapter adap = new MySqlDataAdapter(cmd);
DataSet ds = new DataSet();
adap.Fill(ds);
radGridView1.DataSource = ds.Tables[0].DefaultView;
connection.Close();
}
}
}
}
}
So what could be the solution here to improve the performance of my program?