我希望能够通过将
以下是我目前的代码:
DataTable
转换为IEnumerable<DataRow>
,然后按照列值是否包含在字符串数组中来筛选项目,最后再将其重新转换为DataTable
,因为这是我的方法必须返回的内容。以下是我目前的代码:
string[] ids = /*Gets string array of IDs here*/
DataTable dt = /*Databasecall returning a DataTable here*/
IEnumerable<DataRow> ie = dt.AsEnumerable();
ie = ie.Where<DataRow>(row => ids.Contains(row["id"].ToString()));
/*At this point I've filtered out the entries I don't want, now how do I convert this back to a DataTable? The following does NOT work.*/
ie.CopyToDataTable(dt, System.Data.LoadOption.PreserveChanges);
return dt;
IEnumerable
而不是DataTable
,你会发现实际上DataTable
是作为目标对象的。 - Dennis Röttger