static void Main(string[] args)
{
DataTable datatable1, datatable2;
var row1 = datatable1.Rows.Cast();
var row2 = datatable2.Rows.Cast();
var except1 = row1.Except(row2, new DataRowEqualityComparer());//1在2中不存在的
var except2 = row2.Except(row1, new DataRowEqualityComparer());//2在1中不存在
var except = except1.Union(except2).ToArray();//拼起来
}
class DataRowEqualityComparer : IEqualityComparer//只比较主键
{
public bool Equals(DataRow x, DataRow y)
{
return x["ID"].Equals(x["ID"]);
}
public int GetHashCode(DataRow obj)
{
return obj["ID"].GetHashCode();
}
}
你是不是应该只把3号数据取出来保存?