比较两个DataTable [英] Comparing Two DataTables
问题描述
我有两个DataTable,我需要比较两者。我需要的是Table1中的一行与Table2中的一行匹配(意味着它们包含相同的数据)然后删除表1中的行
这就是我现在所拥有的,但 远 运行时间太长。我需要知道这是否正确,或者是否有更快的方法来做到这一点。谢谢
列表< DataRow> rowsToRemove = new List< DataRow>();
foreach(newTable.Rows中的DataRow r)
{
foreach(table.Rows中的DataRow r2)
{
if(r == r2) )
{
rowsToRemove.Add(r);
}
}
}
foreach(dataRow r in rowsToRemove)
{
newTable.Rows.Remove(r);
}
newTable.AcceptChanges();
这就是我现在所拥有的,但需要 远
<强>跑得太久了。我需要知道这是否正确,或者是否有更快的方法来做到这一点。谢谢
https://social.msdn.microsoft.com/Forums/vstudio/en-US/3aa9d793-4cd8-492f-b860-36fc6faa36be/你能加快速度吗?论坛= vbgeneral
I have two DataTables, and I need to compare the two. What I need is when a row in Table1 matches a row in Table2 (meaning they contain the same data) then delete the row in Table 1
This is what I have right now, but it takes far too long to run. I need to know if this is even correct, or if there is a faster way to do this. Thanks
List<DataRow> rowsToRemove = new List<DataRow>(); foreach (DataRow r in newTable.Rows) { foreach (DataRow r2 in table.Rows) { if(r == r2) { rowsToRemove.Add(r); } } } foreach (DataRow r in rowsToRemove) { newTable.Rows.Remove(r); } newTable.AcceptChanges();
This is what I have right now, but it takes far too long to run. I need to know if this is even correct, or if there is a faster way to do this. Thanks
https://social.msdn.microsoft.com/Forums/vstudio/en-US/3aa9d793-4cd8-492f-b860-36fc6faa36be/can-you-speed-up-the-below-function?forum=vbgeneral
这篇关于比较两个DataTable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!