private DataTable _dt2;
public Form1()
{
InitializeComponent();
_dt1 = new DataTable();
_dt2 = new DataTable();
}
private void Form1_Load(object sender, EventArgs e)
{
_dt1.Columns.Add(new DataColumn("Root", typeof(string)));
DataRow r;
for (int i = 1; i < 6; i++)
{
r = _dt1.NewRow();
r["Root"] = i;
_dt1.Rows.Add(r);
}
_dt2.Columns.Add(new DataColumn("Root", typeof(string)));
for (int i = 1; i < 11; i++)
{
r = _dt2.NewRow();
r["Root"] = i;
_dt2.Rows.Add(r);
}
}
private void btnAction_Click(object sender, EventArgs e)
{
IEnumerable<DataRow> Query1 = _dt1.AsEnumerable();
IEnumerable<DataRow> Query2 = _dt2.AsEnumerable();
DataTable dt = Query2.Except(Query1, DataRowComparer.Default).CopyToDataTable();
dataGridView1.DataSource = dt;
}
結果如下:
沒有留言:
張貼留言