Select single column data from DataTable to list
asp.net, c#
Solution
You don't need anonymous type at all. Try that:
claimNos = dtCpt.AsEnumerable()
.Select(s => s.Field<long>("CLAIM_NUMBER"))
.Distinct()
.ToList();
Problem
I have a datatable, `dtCpt` which has multiple columns in it. It has a column named `CLAIM_NUMBER`. I have a list `List<long> claimNos;` I need all the distinct `CLAIM_NUMBER` from datatable `dtCpt` to the list `claimNos`. I write a code like this ``` claimNos = dtCpt.AsEnumerable().Select(s => new { id = s.Field<long>("CLAIM_NUMBER") }).Distinct().ToList(); ``` but it show an error like this Cannot implicitly convert type 'System.Collections.Generic.List' to 'System.Collections.Generic.List' Is there any easy way to do this in a single line of code?