码迷,mamicode.com
首页 > 其他好文 > 详细

对datatable进行linq过滤

时间:2016-03-20 10:26:22      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:

实例:

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过滤

标签:

原文地址:http://www.cnblogs.com/yinchuan/p/5297161.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!