开发者

Using LINQ-to-objects to create a DataTable from a collection

开发者 https://www.devze.com 2023-03-21 06:52 出处:网络
In my VB.NET code, I have something like this: A collection of clsEmployees, which is made up of clsEmployee objects.

In my VB.NET code, I have something like this: A collection of clsEmployees, which is made up of clsEmployee objects.

I would need a LINQ statement, such that it would return me a DataTable, made up of rows of fields of clsEmployee, which are supposedly firstname, lastname, employeeID, phone, city etc.

Also, the LINQ statement should return only 开发者_运维百科those rows where phone is not null.


Something like

var aList = empList
             .Where((e) => e.phone != null)
             .Select((e) => new { firstname : e.firstname, lastname : e.lastname });  // etc

If you really need rows you can use new DataRow(...) in the select.

0

精彩评论

暂无评论...
验证码 换一张
取 消