Is there linq query tow subtract tow datatable column values? pls help

For eg

Amount Forex
-10306.97 1234
3362.28 5678
-10306.97 1234
3362.28 5678

How to find the differencr between Amount-Forex and save the difference in amount column


  1. Use Read Range activity to read the data from excel and store it in a dataTable variable.

  2. And then use For Each Row activity to iterate that DataTable

                            ForEach row in DT
                               row("Amount") = Cdbl(row("Amount").Tostring) - Cdbl(row("Forex").Tostring)

read the fille and then add one column into that datatable say total and loop through it and store amount in one variable amount=row(“Amount”) and forex = row(“Forex”) and then sum it in 3ed variable sum = amount + forex then assign this value into datatable like this row(“total”) = sum

So you can use Linq to determine the difference.

The Linq to determine the difference would be:
((From dr As Datarow In dtTest Select Convert.ToDouble(dr("Amount"))-Convert.ToDouble(dr("Forex"))).toArray())

This puts the difference as an Array [Double]

but as there is no nice way to do this, it would be easier to simply use a For Each Row activity as @lakshman suggested

1 Like

Thanks bro actually i have missed the Cdb1 in linq to difference now working

dta.Select().ToList().ForEach(Sub(row) row(“Amount”)=CDbl(row(“Amount”).Tostring) - CDbl(row(“Forex”).Tostring))


bro is ther any way in linq to change date format for all values datatable columns

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