如何比较两个数据集的相等性

时间:2021-07-16 16:14:27

I have two datasets each with one data table pulled from different sources and I need to know if there are any differences in the data contained in the data tables. I'm trying to avoid looping and comparing each individual record or column, although there may be no other way. All I need to know is if there is a difference in the data, I do not need to know the details of any difference.

我有两个数据集,每个数据集有一个从不同来源提取的数据表,我需要知道数据表中包含的数据是否有任何差异。我试图避免循环和比较每个单独的记录或列,虽然可能没有其他方法。我需要知道的是,如果数据存在差异,我不需要知道任何差异的细节。

I have tried the below code, but it appears that dataset.Merge does not update rowstatus so dataset.HasChanges() always returns false. Any help is appreciated:

我尝试了下面的代码,但似乎dataset.Merge没有更新rowstatus所以dataset.HasChanges()总是返回false。任何帮助表示赞赏:

var currentDataSet = GetSomeData();
var historicalDataSet = GetSomeHistoricalData();

historicalDataSet.Merge(currentDataSet);

if (historicalDataSet.HasChanges()) DoSomeStuff();

1 个解决方案

#1


I don't know of any built-in support for this and I wouldn't expect it either. So you'll have to do this by yourself in some way.

我不知道有任何内置的支持,我也不会指望它。所以你必须以某种方式自己做。

The most obvious way would be a brute force, table by table and row by row approach.

最明显的方式是蛮力,逐桌和逐行方法。

If you can rely on certain factors to be the same, ie exactly the same naming, ordering of records etc then you could test if saving both as XML and comparing the results might be an efficient trick.

如果您可以依赖某些因素,即完全相同的命名,记录顺序等,那么您可以测试将两者保存为XML并比较结果可能是一种有效的技巧。

#1


I don't know of any built-in support for this and I wouldn't expect it either. So you'll have to do this by yourself in some way.

我不知道有任何内置的支持,我也不会指望它。所以你必须以某种方式自己做。

The most obvious way would be a brute force, table by table and row by row approach.

最明显的方式是蛮力,逐桌和逐行方法。

If you can rely on certain factors to be the same, ie exactly the same naming, ordering of records etc then you could test if saving both as XML and comparing the results might be an efficient trick.

如果您可以依赖某些因素,即完全相同的命名,记录顺序等,那么您可以测试将两者保存为XML并比较结果可能是一种有效的技巧。