代码之家  ›  专栏  ›  技术社区  ›  CaffGeek

DataTable。GetChanges()不断返回NULL

  •  3
  • CaffGeek  · 技术社区  · 16 年前

    allData 但不是在 removeData

    public static DataTable RemoveDuplicateRows(DataTable allData, 
        DataTable removeData) 
    {
        removeData.Merge(allData);
        DataTable newData = removeData.GetChanges(); 
        removeData.RejectChanges();
        return newData;
    }
    

    newData DataTable newData = removeData.GetChanges();

        public static DataTable RemoveDuplicateRows(DataTable allData, DataTable removeData) 
        {
            DataTable duplicate = allData.Clone();
            foreach (DataRow row in allData.Rows)
            {
                duplicate.ImportRow(row);
            }
            foreach (DataRow row in duplicate.Rows)
            {
                row.SetAdded();
            } 
    
            removeData.Merge(duplicate);
            DataTable newData = removeData.GetChanges(DataRowState.Added);
            removeData.RejectChanges();
            allData.RejectChanges();
            return newData;
        }
    
    2 回复  |  直到 11 年前
        1
  •  0
  •   MusiGenesis    16 年前

    DataTable.GetChanges() 方法取决于 DataRow.RowState 财产。对于一对数据表中的每一行 DataTable.Merge() 这意味着,当您将两个数据表与具有“未更改”行状态的行合并时,合并的表还将包含“未更改的”行和数据表。GetChanges方法将返回null或Nothing。

        2
  •  1
  •   satbot    11 年前

    removeData DataTable需要与具有相同的列/字段 allData 换句话说,它不能只是一个新的DataTable()。