Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I need a code in C# which compare two CSV file and saving the not matched column number and data in 3rd CSV file.
CSV can have 1 lakh rows and 30 columns.
Posted
Updated 28-Oct-15 2:09am
v2
Comments
phil.o 28-Oct-15 5:53am    
Not a question.
Andreas Gieriet 28-Oct-15 16:30pm    
The difficult thing is to distinguish between a different record and an additional/missing record. How to synchronize where to continue searching for matches? Or are both CSV files assumed to be of same number or records and same "sorting" or records?
Regards
Andi
Member 12093779 29-Oct-15 3:20am    
Ya both csv will have same number of records and same column name

Write a (possibly fast) CSV parser and do the job.
Have a look at this Code Project article: "A Fast CSV Reader"[^].
 
Share this answer
 
v2
Assuming your CSV files to be compared have the same column "names" then if you have access to SQL Server, SQL server express would do, then I'd suggest importing each CSV file into separate tables (use T SQL "BULK INSERT") and using SQL queries to identify which rows have columns that don't match. You can use the query output to generate (e.g. from a dataset) your output CSV file.

Lakh (100,000?) row comparisons in SQL are likely to be faster than anything you can write yourself.

See solution 1 for the following question for a few hints on how to import CSV files into SQL server from code. *Warning* you'll need to modify it a bit for your problem if you do decide to try this approach.

SQL Procedure with insert[^]

If you've got access to SQL server DBs via SQL Server Manager (or whatever it's called this week) and this is not a procedure that needs automating then there is (or used to be) a wizard that will guide you through importing a CSV file.
 
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