我们创建了一个合并2个数据表的函数。
这是代码
Public Shared Function CompareTwoDataTable(ByVal dt1 As DataTable, ByVal dt2 As DataTable) As DataTable
dt1.Merge(dt2)
Dim d3 As DataTable = dt2.GetChanges()
Return d3
End Function
我想知道代码是不正确还是什么,我的观点是我想确定这两个表之间的区别并获得它们的区别。
提前致谢
答案 0 :(得分:0)
对于那些查看此内容的人来说,这是我已经提出的代码
我已经创建了一个使用其ID比较2数据表的函数
Public Shared Function CompareTwoDataTable(ByVal dt1 As DataTable, ByVal dt2 As DataTable) As DataTable
Dim rows_to_remove As New List(Of DataRow)()
For Each row1 As DataRow In dt1.Rows
For Each row2 As DataRow In dt2.Rows
If row1("ID").ToString() = row2("ID").ToString() Then
rows_to_remove.Add(row1)
End If
Next
Next
For Each row As DataRow In rows_to_remove
dt1.Rows.Remove(row)
dt1.AcceptChanges()
Next
Dim d3 As DataTable = dt1
Return d3
End Function
希望有所帮助