I want to remove the columns that have not a certain name. I have been searching but can't find something that can help me.
This is what I am trying:
DataColumnCollection columns = dtExcelInforme.Columns;
foreach (DataColumn col in columns)
{
if ((col.ColumnName != "Code") || (col.ColumnName != "Denomination"))
{
dtExcelInforme.Columns.Remove(col);
}
}
But this doesn't work because I am modifying the collection of columns.
How can I do it? Thanks in advance!