将一个数据表中的数据与另一数据表中的数据进行比较 [英] compare data in one datatable against the data in another

查看:77
本文介绍了将一个数据表中的数据与另一数据表中的数据进行比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有两个数据表.
dtToBeChecked和dtCriteria
dtCriteria是一组记录,其中包含dtToBeChecked中每个字段的条件.
需要对照dtCriteria检查dtToBeChecked内部的记录,以查看数据是否匹配. (尝试确保dtToBeChecked中的数据全部有效并且匹配dtCriteria中的条件,如果dtToBeChecked中的值之一与dtCriteria中的值不匹配,则返回false).
例如,dtToBeChecked中的字段都存在于dtCriteria中.然后将对照dtCriteria中输入字段的值检查dtToBeChecked中的值.

我决定:
1-遍历dtToBeChecked中的行
2-获取字段名称和单元格值
3-循环遍历dtCriteria中的行,看看是否有匹配项.
4如果没有匹配项,则返回false.

我要纠正的是什么吗?

谢谢

Hi,
I have two datatables.
dtToBeChecked and dtCriteria
dtCriteria is a set of records which have criteria for each field in dtToBeChecked.
The records inside dtToBeChecked need to be checked against dtCriteria to see if the data match. (Trying to make sure that the data in dtToBeChecked are all valid and match the criteria in dtCriteria and if one of the values in dtToBeChecked does not match what is in the dtCriteria then return false).
For example, the fields in dtToBeChecked are all present in dtCriteria. And the values in dtToBeChecked will be checked against the values for the entered fields in dtCriteria.

I have decided to:
1- loop through the rows in dtToBeChecked
2- get the fieldname and cell value
3- loop through the rows in dtCriteria and see if there is a match.
4 return false if there is no match.

Is what I am trying to do correct?

Thanks

推荐答案

对我来说,这不是一个好方法.因为您的迭代是 number_records_in_table_1 * number_records_in_table_2

我有以下选择,
-按唯一ID对两个表进行排序. (我希望您有一个这样的键,这是拥有唯一键的优点之一)
-一次踩到两个表并比较ID.如果发现不匹配,则比较失败.您可以记录数据,然后做任何您想做的事情.

要进行更多改进,您可以遍历第一个表并将所有唯一ID加载到字典中.然后遍历第二个表并与字典进行比较.
For me it''s not a good approach. Because your iteration is number_records_in_table_1 * number_records_in_table_2

I have an options as follows,
- Sort both tables by a unique ID. (I hope you have a such, and this is one of the advantages having a unique key)
- Step on both tables at once and compare the IDs. If you find a mismatch then the comparison is failed. You can log data and do whatever you want at that point.

Improving more that, you can traverse through the first table and load all the unique IDs to a dictionary. Then traverse through the second table and compare against the dictionary.


http://forums .asp.net/t/1459790.aspx [ ^ ]



http://forums.asp.net/t/1459790.aspx[^]

or

http://stackoverflow.com/questions/164144/c-how-to-compare-two-datatables-a-b-how-to-show-rows-which-are-in-b-but-not[^]


这篇关于将一个数据表中的数据与另一数据表中的数据进行比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆