0

I am working on a project basically the flow as writtien below Read 2 Csv files Compare its content row by row and column identify rows which differ, even by a column Create a new Csv file to contain the difference

Problems encountered:

  1. I cannot read the csv file and store them inj the datatable. I can do it with xslx(excel file) keeps giving error on wrong file location

I am suspecting its a connection string error

i was using this String:

connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + FileDirectory + ";Extended Properties=\"Text;HDR= Yes;FMT = Delimited\"";

Oledbconnection Connection = new OleDbConnection(connectionString);

OleDbDataAdapter Adapter = new OleDbDataAdapter("select * from [" + Filesheet + "$]", Connection);
  1. I am using Oledbconnection method, s there a more efficient method? without storing would be preferable

  2. How do i run the program whereby it will autmatically access the file, the files are contain in 2 different folders and compare them file by file,as so far i only manage to do a particular file read

  3. Do you guys have a better alternative way to solve this problem?

2
  • 5
    you want it in c# , why tag java ??? Commented Mar 15, 2013 at 6:29
  • Do those CSV lines have some kind of primary key, or is it just: if (file1.Lines[i] != file2.Lines[i]) { file3.WriteLine(file2.Lines[i])}? Commented Mar 15, 2013 at 8:08

2 Answers 2

1

I've never tried opening a csv file with a connection string.

CSV files are basically just delimited by rows with \n (or \r\n) and columns by , (or whatever).

So what I personally do is usually open it using a TextReader - and do the following

foreach (string row in textString.Split('\n')
{
foreach (string cell in row.Split(',')
{
//One cell at a time

}
}

There are libraries for opening csv files, but I find this is the simplest generally.

3.) Well, you'll have to run the code 'twice' using a different file. If they're hard coded use an array - or you can pop up a number of OpenFileDialog to ask the user to pick them

Otherwise having issues understanding your problem.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.