Click here to Skip to main content
15,903,201 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I need to compare table records in c#. I have decided to do it with Hashtable. Should I append all the column values and add it with a key to Hashtable then compare the strings together to detect difference or there is a better way?
Posted
Comments
Philippe Mori 7-Jul-11 20:17pm    
Why would you that?
Mastersev 8-Jul-11 14:46pm    
I will have to do it in c# and I will have to go through every single row (total 130000 rows). I have been advised to use hashtables to detect the difference faster in rows and update the target database row. I have to keep 2 databases synced using this application.

"Should I append all the column values" - doesn't sound quite right.

Create a class representing the row data, don't convert column data to strings, if it's a date use DateTime, if its a bigint use long, and so on.

Implement the IComparable[^] on your row class.

Create a class implmenting IComparer<> for your class - That's easy when you have implemented IComparable.

Create a SortedSet[^] - you will not be allowed to add duplicates.

Or do as Christian advices - perform the operations using SQL in the database.

Best regards
Espen Harlinn
 
Share this answer
 
I'm not sure why you 'decided' to use a hashtable before deciding if that will do what you want. I would think it depends on what you mean by 'table'. If you mean SQL tables and you're looking only for exact matches, your best bet is to do that in the database, not in C# code.
 
Share this answer
 
Comments
Espen Harlinn 7-Jul-11 20:17pm    
Good point
Add an index on your database based on the most important fields. Then retreiving records in that order will ensure that identical record are returned together.

Group the result by that key and and then compare all remainding fields and you will find all duplicates.
 
Share this answer
 

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