如何比较两个结构相同的DataTable并将不同的记录输出到另一个DataTable中?急!

解决方案 »

  1.   

    在ado.net中好像只能一条一条的比较和处理。
      

  2.   

    利用循环,遍历DataTable的DataRow,然后利用DataRow.Equals();
    如DataTable1.Rows[i].Equals(DataTable2.Rows[i]),如果相同则得到true,否则false
      

  3.   

    这样循环只能校验相应行位置的数据,不相对应的行如何比较?
    public DataTable GetExcludeData(DataTable MasterDT,DataTable InvalidDT)
    {
    int nCols = MasterDT.Columns.Count;
    //Define the Excluded Data
    DataTable dtExclude = new DataTable();
    dtExclude = MasterDT.Clone();
    //Select the Invalid Data
    foreach(DataRow dtrM in MasterDT.Rows)
    {
    for(int n=0; n<nCols; n++)
    {
    if(!MasterDT.Rows[n].Equals(InvalidDT.Rows[n]))
    {
    dtExclude.ImportRow(dtrM);
    break;
    }
    }
    }
    return dtExclude;
    }
      

  4.   

    有两个DataTable如下, 如何将两个DataTable中不同的记录行输出?Table1
    Column1  Column2  Column3  Column4
    11111    222222   3333333  4444444
    22222    222222   3333333  4444444
    33333    222222   3333333  4444444
    44444    222222   3333333  4444444
    55555    222222   3333333  4444444Table2
    Column1  Column2  Column3  Column4
    11111    222222   3333333  4444444
    33333    222222   3333333  4444444
    55555    222222   3333333  4444444
      

  5.   

    想要一个一个比较,相当一个笛卡尔积的量了.(我也不知c#是否提供了different(tab1,tab2)这种
    东东.呵呵.
    a1表,a2表 比较次数 a1.count*a2.count
    for i=0 to a1.count
        for j=0 to a2.count
          if a1.fields1!=a2.fields1&&a1.fields?!=a2.fields?
             在这里就将找到的放入一个datatable中去,如tabResult然后输出tabResult
    简单说了下,没有用c#来写这段code