How to Compare datatable row values using linq

Hello everyone,

Using linq I want to compare each cell value in the first row of datatable is greater than some threshold (Assume 0.8) . Below is the screenshot for reference

Capture

Some times the cell may contain null value

Could any one help on this

Hi!

have a view on this thread and made some changes according to your requirement

Regards,
NaNi

@ushu

when only first row is to check we would recommend to implement it with essential activities.

For Training purpose have a look here:
Variables:


grafik

Linq:

(From d In dtData.AsEnumerable
Let ias = d.ItemArray.Select(Function (x) If(isNothing(x) OrElse String.IsNullOrEmpty(x.toString.Trim), "0",x.toString))
Let chk = ias.Select(Function (x) If(Double.TryParse(x, Nothing), x,"0")).All(Function (x) CDbl(x) >0.8)
Where chk
Select r=d).ToList

when any col value is null, empty or not parseable we set its value to 0

grafik

Find starter help here:
Filter_AllCols_GreaterINTThreshold.xaml (8.3 KB)

Thanks Peter. I am checking it

Thanks Peter. Its working . I have another scenario where I have to compare each value in an alternative columns. Below is the screenshot

Capture

Have to compare highlighted ones with the threshold (0.8)

Please suggest if it is possible with linq

lets try toscope topics to only one case. Thats easier for other members for finding solutions.

In case of we want to check only a col set we can try:

arrColset|DataType: String() = {"Inv-Conf", "PO-Conf"}

(From d In dtData.AsEnumerable
Let ias = arrColset.Select(Function (x) If(isNothing(d(x)) OrElse String.IsNullOrEmpty(d(x).toString.Trim), "0",d(x).toString))
Let chk = ias.Select(Function (x) If(Double.TryParse(x, Nothing), x,"0")).All(Function (x) CDbl(x) >0.8)
Where chk
Select r=d).ToList

Thanks Peter

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.