Sunday, 25 August 2013

How to remove DataTable column in c#

We can remove Column in DatatTable by using DataColumnCollection.Remove method as follows.

private void RemoveColumnByName(string columnName)
    {
        // Get the DataColumnCollection from a DataTable
        DataColumnCollection columns =dt.Columns;

        if (columns.Contains(columnName))
            if (columns.CanRemove(columns[columnName]))
                columns.Remove(columnName);
    }

No comments: