我在应用程序中使用以下代码使用计时器更新 DataGridView。计时器每秒运行一次,会使屏幕闪烁。如何才能避免屏幕闪烁?或者还有另外一种更新 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();
ALTER DATABASE yourDB SET ENABLE_BROKER
)。祝你好运! - alex555