2个数据表之间的差异
我有 2 个 DataTable,我想创建第三个 DataTable,其中包含 DataTable 1 和 DataTable 2 之间的差异。
例如,DataTable1 具有原始数据,而 DataTable 2 只是一个副本,就像复制一样。但是,当您在 DataTable1 中插入新行时,DataTable2 刚刚插入了同一行。现在我的代码在DataTable1和DataTable2之间进行比较,如果不等于(插入1行或更多行),则DataTable2再次记录DataTable1中的所有数据。
我如何执行选择命令来执行此差异并将这些数据记录在第三个 DataTable 中?
I have 2 DataTable and I want to create a third DataTable that contais the difference between DataTable 1 and DataTable 2.
For example, DataTable1 has the original data, and the DataTable 2 is just a copy, like a replication. But when you insert a new row in DataTable1, the DataTable2 has just insert the same row. Nowaday my code do a compare between DataTable1 and DataTable2, if not equals (1 row or more was inserted), DataTable2 record all data from DataTable1 again.
How can I do a select command, that do this difference and record those datas in a third DataTable ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试这样的事情:
Try something like this:
我会考虑有两列来标识表
(col1,col2)
I will consider that there are two columns to identify the tables
(col1,col2)
仅使用 SQL,您可以使用
UNION
轻松查找差异,这里有一篇关于该主题的优秀文章:http://weblogs.sqlteam.com/jeffs/archive/2004/11/10/2737.aspx当表匹配时,查询将返回空行集,否则返回不同的行。
Using only SQL you can use
UNION
to easily find differences, there is an excellent article on the subject here: http://weblogs.sqlteam.com/jeffs/archive/2004/11/10/2737.aspxThe query will return an empty row set when the tables match, otherwise the differing rows are returned.