Selectively retrieving data from DataTable

as an alternate
Lets assume that strJOBCode / strLocationCode are string Variables which we use for filterings

(From d In dtData.AsEnumerable
Group d By k=d("Location Code").toString Into grp=Group
Where k.Equals(strLocationCode)
Let embr = grp.Where(Function (x) IsNothing(x("Job Code")) OrElse String.IsNullOrEmpty(x("Job Code").toString.Trim))
Let fmbr = grp.Where(Function (y) y("Job Code").ToString.Trim.Split(","c).Contains(strJobCode))
Let res = If(fmbr.Count > 0, fmbr, embr)
Let ret = If(res.Count > 0, res.First()("Job Code").toString, "UNDEFINED")
Select sap = ret).First()

it will be prepared for handling some covered requirements e.g. what is to do if code is not found but no row with empty Job Code exists (returns UNDEFINED)
and others

The group by approach can also be adopted to an Filter Approach

The reason of splitting the LINQ part result is to have a chance to return part result in case of LINQ Statement/Bug Analysis needs. So we can reduce the LINQ Blackbox for this

2 Likes