I use below code to update datagridview in my application with Timmer. Timmer runs in everysecond and it keeps the screen flashing. How can i change not to flash at the time? or another way to update datagridview?
SqlConnection mySqlConnection = new SqlConnection(SQLCONN);
mySqlConnection.Open();
SqlDataAdapter addapter = new SqlDataAdapter();
DataTable dt = new DataTable("SSReportAmalgamate");
SqlCommand cmd = mySqlConnection.CreateCommand();
cmd.CommandText = "EXEC App_GetDATA " + "@acc" + "," + "@selecttype";
cmd.Parameters.Add("@acc", SqlDbType.Char).Value = acc;
cmd.Parameters.Add("@selecttype", SqlDbType.Char).Value = type;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandType = CommandType.Text;
cmd.Connection = mySqlConnection;
addapter.SelectCommand = cmd;
addapter.Fill(dt);
dataGridView1.DataSource = dt;
mySqlConnection.Close();
The problem is, that you update the form even the data has not been changed. Instead, try to hear to an event from the SQL Server e.g. using a SqlDependency when there is new data (of course, if your data changes not often).
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