0

I have the following which has worked for me so far, however I now want to only select locations if another column (Location ID) is not null. How do I add this filter to my list?

Location and Location ID are both columns in datatable dt.

EDIT: edited code to try to match what was in the comments. I also tried != "" and the list isn't populated either way.

Last edit: The below code didn't work because I had dt as var originally. Removing the var and just declaring the datatable fixed it and it now works correctly.

var distinctLocs = dt.AsEnumerable()
               .Where(s => s.Field<string>("Location ID") != null)
               .Select(s => new
               {
                   id = s.Field<string>("Location"),
               })
               .Distinct().ToList();
Nguyễn Văn Phong
  • 13,506
  • 17
  • 39
  • 56
Mikael
  • 1,002
  • 1
  • 11
  • 22

0 Answers0