我有很大的数据表我想要得到psented的数据表或者该数据表重新$ P $的子集。 简要说我怎么在数据表中选择特定列。
I have big DataTable I want to get subset of this DataTable represented as DataTable either. Briefly saying how do I select particular columns in DataTable.
我是想这样的事情,但它不工作...
I was trying something like this but it doesn't work...
DataTable dTable = new DataTable();
...
...
...
DataTable dt = from field in dTable
where field.Field<string>("Manager")
where field.Field<string>("Phone")
select field;
也许我的code是错的,我怎么得到经理人和手机列从一个数据表到另一个没有循环想到呢?
Maybe my code is wrong, how do I get "managers" and "Phone" columns from one DataTable to another without looping thought it?
引用的DataTableExtensions -
Reference the DataTableExtensions -
的http://msdn.microsoft.com/en-us/library/system.data.datatableextensions.asenumerable.aspx
然后...
var whatever = dTable.AsEnumerable();
然后按MSDN的例子...
Then per the MSDN example...
var productNames = from products in table.AsEnumerable()
select products.Field<string>("ProductName");
编辑/更新:不幸的是,我不认为这是一个建在直接投回到以不同架构的DataTable。您有无使用数据表?我相信......因为它可能是太多精力重构和测试code。祝你好运,让我们作为使用强类型的列表的工作都更加的乐趣的。
Edit/update: Unfortunately I do not think there is a built in direct cast back to a DataTable with a different schema. You have to use a DataTable? I believe it... as it might be too much effort to refactor and test your code. Good luck and keep us posted as working with strongly-typed lists are much more fun.