//比较两个数据源的交集
dt1.AsEnumerable().Intersect(dt2.AsEnumerable(), DataRowComparer.Default).CopyToDataTable();
//获取两个数据源的并集 dt1.AsEnumerable().Union(dt2.AsEnumerable(), DataRowComparer.Default).CopyToDataTable(); //获取两个数据源的差集 dt1.AsEnumerable().Except(dt2.AsEnumerable(), DataRowComparer.Default).CopyToDataTable(); 注意:结果如果为空则CopyToDataTable会抱错,应该做异常处理。 |