LINQ Query exclude records in select

Larry Brister
Larry Brister used Ask the Experts™
on
My LINQ Query below works fine

However...

There are about 500 empty or zero length records being inserted into the results set.

How do I exclude those records in the select?

            Dim Query = _
            (From Region In dataset1.Tables(0) _
             Select Region.Field(Of String)("Region")).Distinct().OrderBy(Function(item) item).ToList

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Retired
Distinguished Expert 2017
Commented:
Try it like this.

Dim Query = _
    (From Region In dataset1.Tables(0) _
     Where Region IsNot Nothing _
     Select Region.Field(Of String)("Region")).Distinct().OrderBy(Function(item) item).ToList

Open in new window

Larry Bristersr. Developer

Author

Commented:
Put me on the right track.

The final solution was actually this one...
There WAS data there...but it was = ""
Dim Query = _
            (From Region In dataset1.Tables(0) _
             Where Region.Field(Of String)("Region") <> "" _
                    Select Region.Field(Of String)("Region") _
             ).Distinct().OrderBy(Function(item) item).ToList

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial