C# - linq 操作 DataTable

2021-01-28 15:15

阅读:506

标签:style   linq   ace   enum   field   date   head   fir   OLE   

 1 方法一:更简洁
 2             Console.WriteLine(dt.Rows.OfType().First(x => x.Fieldstring>("xx_Name") == "A").Fieldstring>("xx_NO"));   
 3   
 4 方法二:linq 更清晰
 5   
 6             var query = from dr in dt.AsEnumerable()  
 7                               where dr.Fieldstring>("xx_Name") == "A"  
 8                               select dr;  
 9             Console.WriteLine(query.First().Fieldstring>("xx_NO"));
10  
11 通过linq对现有的DataTable进行查询,并将结果拷贝至新的DataTable中
12 // Query the SalesOrderHeader table for orders placed 
13 // after August 8, 2001.
14 IEnumerable query =
15     from order in orders.AsEnumerable()
16     where order.Field("OrderDate") > new DateTime(2001, 8, 1)
17     select order;
18  
19 // Create a table from the query.
20 DataTable boundTable = query.CopyToDataTable();

 

C# - linq 操作 DataTable

标签:style   linq   ace   enum   field   date   head   fir   OLE   

原文地址:https://www.cnblogs.com/rickyliu/p/11888168.html


评论


亲,登录后才可以留言!