I have a csv file with 35+ columns, it then gets placed into a data table using my csv reader, I want to find 4 columns by name then remove the rest, the 4 columns could be at random indexes so I want to search for the name of the header.
So far I have this:
DataTable dataTable = new DataTable();
dataTable = CSVReader.CSVInput(filepath);
foreach(DataColumn dataColumn in dataTable.Columns)
{
if(dataColumn.ColumnName != "Cat" || dataColumn.ColumnName != "Dog" || dc.ColumnName != "Turtle " || dc.ColumnName != "Lion")
{
dataTable.Columns.Remove(dataColumn)
}
}
Cat, Dog, Turtle and lion are the examples of the columns I want to keep
This just removes the first column and displays an error saying the "Collection was modified".
I want to do this so I can then sqlbulkcopy the datatable.
EDIT
creating another data table will run out of memory