Compare CSV files to get modified records

ashok.k

Member
Joined
Jun 26, 2009
Messages
13
Programming Experience
Beginner
Hi

I am working on a .NET 4.0 desktop application. Application reads the CSV files daily and update the values in the Database.

Every row in the CSV file has an unique user Id. The details of every user may or may not change daily.

Application has to read the CSV and check if any of the values in the file has changed. Or if any new users with new user Ids are added to the CSV.

We have a local mater CSV which would be in Sync with the database. When Database is updated this master CSV will also be updated.

How to compare the incoming CSV with the local master CSV to check if any of the values in the incoming files has changed?

How to filter only the modified users or new users from the incoming files?

Can LINQ be used to compare the CSV files and get only the modified or newly added users?

Thanks

Ashok
 
The easiest way is to make lists of the values and simply 'subtract' one form the other ...

        Dim master As List(Of String) = System.IO.File.ReadAllLines(masterfile).ToList ' read master 
       Dim newcsv As List(Of String) = System.IO.File.ReadAllLines(amendedfile).ToList ' read current file
        Dim Changes As List(Of String) = New List(Of String)(newcsv.Except(master)) ' get list of all changed or new lines
 
Hi,

Thanks for your reply. How to get the exact difference? What value is changed and I would like to update the new value in database and also in Master CSV file.

thanks
Ashok
 
Back
Top