C# 中 Linq 操作 DataTable

  方法一:更简洁
            Console.WriteLine(dt.Rows.OfType<DataRow>().First(x => x.Field<string>("xx_Name") == "A").Field<string>("xx_NO"));   
  
方法二:linq 更清晰
  
            var query = from dr in dt.AsEnumerable()  
                              where dr.Field<string>("xx_Name") == "A"  
                              select dr;  
            Console.WriteLine(query.First().Field<string>("xx_NO"));  

 

posted @ 2017-07-28 09:35  沉迷编程的程序员  阅读(2271)  评论(0编辑  收藏  举报