/// <summary> /// 多条件的过滤返回DataTable /// </summary> /// <param name="dataTable"></param> /// <param name="filterConditions"></param> /// <returns></returns> private DataTable MuilteExpressionFilter(DataTable dataTable,List<dynamic> filterConditions) { var filteredRows = dataTable.AsEnumerable() .Where(row => { foreach (dynamic condition in filterConditions) { if (condition.Key != null && condition.Value != null) { string fieldName = condition.Key.ToString(); string fieldValue = condition.Value.ToString(); if (row[fieldName].ToString() != fieldValue) { return false; } } } return true; }); // 创建新 DataTable 存储过滤结果 DataTable filteredDataTable = dataTable.Clone(); foreach (DataRow filteredRow in filteredRows) { filteredDataTable.ImportRow(filteredRow); } return filteredDataTable; }
标签:return,列名,filteredDataTable,dataTable,拼接,ToString,DataTable,condition From: https://www.cnblogs.com/LowKeyCXY/p/18157568