Question

In my DataTable, I have columns which begin with #col_. How do I delete only these columns from the table and leave the rest ?

I only know this snippet is needed - table.Columns.RemoveAt(index);

Était-ce utile?

La solution

var colsToRemove= (from DataColumn x in table.Columns
                          where x.ColumnName.StartsWith("#col_")
                          select x.ColumnName);

while (colsToRemove.Any())
    table.Columns.Remove(colsToRemove.First());
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top