我想用后台工作人员填充网格,但我不知道必须在哪里添加DataGrid.DataSource=DataTable;
是否有任何简单的示例可以解释如何使用后台工作人员进行填充DataGrid
?
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
setgride();
}
private void setgride()
{
string constring = "constring";
SqlCommand com = new SqlCommand();
SqlConnection con = new SqlConnection(constring);
com.Connection = con;
com.CommandText = " select * from Request";
SqlDataAdapter adapt = new SqlDataAdapter(com);
DataTable dt2 = new DataTable();
adapt.Fill(dt2);
propdt2 = dt2;
}
private void button1_Click(object sender, EventArgs e)
{
this.backgroundWorker1.RunWorkerAsync();
}