Linq Query - Selective Fields as DataTable?
I want to create a datatable from linq query. The below code selects all filed, but i need select few fileds like "door_no","street_name","city_name","post_code","date of birth" and need to create it as Datatable.
var Results = from SelRow in MyDtb1.AsEnumerable() where SelRow.Field("door_no") != null select SelRow; DataTable ChkRe开发者_运维问答sult = Results.CopyToDataTable();
Any Better Ideas
You need to create an anonymous type like this:
var Results = from SelRow in MyDtb1.AsEnumerable()
where !SelRow.IsNull("door_no")
select new
{
DoorNumber = SelRow["door_no"],
CityName = SelRow["city_name"],
ZipCode = SelRow["post_code"]
};
精彩评论