datacolumncollection

How to remove DataColumn from DataTable programmatically

拥有回忆 提交于 2020-02-15 05:42:08
问题 I have a code foreach (DataColumn dataTableCol in this.dataTable.Columns) { bool columnFound = false; foreach (GRTColumnView uiColumn in descriptor.UIColumns) { if (dataTableCol.ColumnName.Equals(uiColumn.Name)) { columnFound = true; break; } } if (!columnFound) { if (this.dataTable.Columns.Contains(dataTableCol.ColumnName)) this.dataTable.Columns.Remove(dataTableCol.ColumnName); } } I want to remove some "things" from collection if they aren't found in another collection. When I run the

How to remove DataColumn from DataTable programmatically

喜你入骨 提交于 2020-02-15 05:40:12
问题 I have a code foreach (DataColumn dataTableCol in this.dataTable.Columns) { bool columnFound = false; foreach (GRTColumnView uiColumn in descriptor.UIColumns) { if (dataTableCol.ColumnName.Equals(uiColumn.Name)) { columnFound = true; break; } } if (!columnFound) { if (this.dataTable.Columns.Contains(dataTableCol.ColumnName)) this.dataTable.Columns.Remove(dataTableCol.ColumnName); } } I want to remove some "things" from collection if they aren't found in another collection. When I run the

Querying DataColumnCollection with LINQ

送分小仙女□ 提交于 2019-12-03 02:36:55
问题 I'm trying to perform a simple LINQ query on the Columns property of a DataTable: from c in myDataTable.Columns.AsQueryable() select c.ColumnName However, what I get is this: Could not find an implementation of the query pattern for source type 'System.Linq.IQueryable'. 'Select' not found. Consider explicitly specifying the type of the range variable 'c'. How can I get the DataColumnCollection to play nice with LINQ? 回答1: How about: var x = from c in dt.Columns.Cast<DataColumn>() select c

Querying DataColumnCollection with LINQ

别来无恙 提交于 2019-12-02 16:28:27
I'm trying to perform a simple LINQ query on the Columns property of a DataTable: from c in myDataTable.Columns.AsQueryable() select c.ColumnName However, what I get is this: Could not find an implementation of the query pattern for source type 'System.Linq.IQueryable'. 'Select' not found. Consider explicitly specifying the type of the range variable 'c'. How can I get the DataColumnCollection to play nice with LINQ? How about: var x = from c in dt.Columns.Cast<DataColumn>() select c.ColumnName; You could also use: var x = from DataColumn c in myDataTable.Columns select c.ColumnName It will