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
  • 12,566
  • 16
  • 32
  • 51
Mikael
  • 982
  • 1
  • 8
  • 19

0 Answers0