对datatable进行linq过滤
Posted yinchuan
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了对datatable进行linq过滤相关的知识,希望对你有一定的参考价值。
实例:
DataTable data = new DataTable();
data.Columns.Add("schoolid", Type.GetType("System.Int32"));
data.Columns.Add("ccid", Type.GetType("System.Int32"));
DataRow newRow1 = data.NewRow();
newRow1["schoolid"] = 2;
newRow1["ccid"] = 1;
data.Rows.Add(newRow1);
DataRow newRow2 = data.NewRow();
newRow2["schoolid"] = 2;
newRow2["ccid"] = 2;
data.Rows.Add(newRow2);
DataRow newRow3 = data.NewRow();
newRow3["schoolid"] = 1;
newRow3["ccid"] = 2;
data.Rows.Add(newRow3);
string ceshi = "1,2";
var dataSelect = data.AsEnumerable();
dataSelect = from r in dataSelect
where r.Field<int>("schoolid") == 2 && !(new int?[] {int.Parse(ceshi) }).Contains(r.Field<int>("ccid")) select r; foreach (DataRow row in dataSelect)
{
string schoolid = row["schoolid"].ToString();
string ccid = row["ccid"].ToString();
}
以上是关于对datatable进行linq过滤的主要内容,如果未能解决你的问题,请参考以下文章
令人惊讶的性能差异:List.Contains、Sorted List.ContainsKey、DataRowCollection.Contains、Data Table.Select、DataTab