Click here to Skip to main content
15,888,984 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted

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.
 
Share this answer
 
 
Share this answer
 
v4
Comments
André Kraak 14-Oct-11 5:41am    
I made your links click-able.
CodingLover 14-Oct-11 5:45am    
Oh, that may be I couldn't do that. ;) Anyway, now it's more clear.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900