0

I know this could be done manually with some hardcoded Linq Joins. However, I would like to come up with an elegant way to do this in bulk due to the high number of .csv files I have.

Code:

var dir = Directory.EnumerateFiles(@"C:\IIP_2\", "*.csv", SearchOption.AllDirectories);
var dtCombined = new DataTable();
var lst = new List<DataTable>();

foreach (var v in dir) { lst.Add(GetCSVRows(v, true)); }

//Take List<DataTable> and combine into dtCombined ????

How can I combine this List into one, possibly with a Lambda statement ?

Thanks in Advance !

bumble_bee_tuna
  • 3,533
  • 7
  • 43
  • 83

1 Answers1

3

Would this work for you? You should be able to avoid use the list of DataTables altogether.

foreach (var v in dir) 
{ 
    dtCombined.Merge(GetCSVRows(v, true)); 
}

If you change GetCSVRows to return an IDataReader, you can use Load, which may be faster.

foreach (var v in dir) 
{ 
    dtCombined.Load(GetCSVRows(v, true)); 
}
Austin Salonen
  • 49,173
  • 15
  • 109
  • 139