Showing posts with label Remove column. Show all posts
Showing posts with label Remove column. Show all posts

Saturday, November 17, 2012

How to create one data table from other datatable



You can create copy of existing data table and than remove unwanted data columns from data table
Following is code:

DataTable dtSourceCopy = dtSource.Copy();
                    DataColumnCollection columnsArray = dtSourceCopy .Columns;
                    foreach (var item in columnsArray)
                    {
                        if (!selectedColumns.Contains(item.ToString()))
                        {
                            dtSource.Columns.Remove(item.ToString());
                        }
                    }