I have a datatable with column reception_date inside and I want to find the difference between “Now” and reception_date for each row in the datatable.
Right now I am using a while loop and checking if the reception_date is less than today and if yes, increment the counter.
But I have more than 30000 rows in the datatable and to do this with a loop increases the execution time a lot.
Is there any other way to compute this?
Thanks in advance for help,
when it is about counting maybe a LINQ will serve
(From d in dtData.AsEnumerable
Let dp = CDate(d(ColNameOrIndex).toString.Trim)
Where dp.Date < Now.Date
feel free to adopt the line
Let dp = CDate(d(ColNameOrIndex).toString.Trim) to your needs
Hi @yogendra.kulkarni ,
You could opt for
For Each Row in Datatable or make use of
Parallel For Each Activity at first and Check the performance. As it is somewhat an update operation we tend to use the Looping
For Each Row Activity itself.
We could later try for a Linq approach if still the performance is low.
Thanks for the quick response.
Yes I was expecting to use Linq but is it possible to have the difference of each cell in another column lets say date difference?
It’s impossible to do this without looping. It’s a datatable, any solution to do what you want will have to loop. Linq still loops, it’s just hidden from you.
let us sort out understanding missmatches
I guess, wrongly understood was following
today = 23-Sep-2020
A total count of Col1 < today: 2 - 15/17 Sept 2022
it sounds like an update in a data column within the data table. Where we do have the following options:
How to Update Data Column Values of a Data Table | Community Blog
But in general we agree to @supermanPunch for working with For Each Row / For Each
In the Blog also was elaborated that is recomended to send only the needed rows into the update. So filtering with LINQ, updating within For each could be a good balance of both