private DataTable tb;
private void Form1_Load(object sender, EventArgs e)
{
tb= GetData();
this.dataGridView1.DataSource =tb;
}
private DataTable GetData()
{
SqlConnection con = new SqlConnection(app.connstr);
SqlDataAdapter dp = new SqlDataAdapter(cha, con);
DataSet ds = new DataSet("Chu");
dp.Fill(ds, "Chu");
return ds.Tables["Chu"];
}
private void button1_Click(object sender, EventArgs e)
{
DataTable tb1=GetData();
if(tb1!=null)
tb.Merge(tb1);
this.dataGridView1.DataSource = tb;
}
DataTable操作
查询的放在dt1
将查询的dt1 加入到dt2中