【求助】怎么判断两个表里的某一行是相同的?
1.如题,我判断的了两个表是这样的:
dtCheckThen表
dtCheck表
2.我写的代码如下,判断失败了:
for (int i=0; i < dtCheck.Rows.Count;i++ )
{
    for (int j = 0; j < dtCheckThen.Rows.Count; j++)
    {
         if (dtCheckThen.Rows[j] == dtCheck.Rows[i])
         {
             MessageBox.Show("两表中有相同项!");
         }
     }
}
------解决方案--------------------         if (dtCheckThen.Rows[j].AsEnumerable().Any(x =>  dtCheck.Rows[i].AsEnumerable().Select(y => y.ToString()).Contains(x.ToString())))
         {
             MessageBox.Show("两表中有相同项!");
         }
当然,你用的方法效率是很低的。最好先排序,然后直接比较。
------解决方案--------------------先排序,再比较
比如
7 1 3 8 2
和
4 3 6 9 0 5
问你有多少相同的,你怎么比
是不是先排序成
1 2 3 7 8
0 3 4 5 6 9
然后拿第一个和第一个比,如果哪个小,就拿它的下一个再去比,这样比较快,只要一趟?
------解决方案--------------------   if (dtCheckThen.Rows[j].AsEnumerable().Any(x =>  dtCheck.Rows[i].AsEnumerable().Contains(x)))
         {
             MessageBox.Show("两表中有相同项!");
         }