Can i Use linq queries instead of For each loop

Hi everyone,

I need to excel reconciliation between 2 excel sheets where I loop through each and every row of one excel sheet, retrieve data and compare it with other excel sheet’s record, for this I am using for each row in datatable. Since the excel sheet has 50k records, its taking almost 1 hour time to loop into each record and compare it with the other.
For which, I got a suggestion from my higher manager telling that, using LINQ queries I can reduce processing time instead of for each row.

How do use this?
can anyone help me with this.


it can have a chance to solve it alternate
Just share with us some sample input and the exepected output

Stepping into Linq have a look here:

In this current project, I need to do group by invoice number and sum of debit amount column and then i have to compare it with other excel sheet respective invoice number’s debit amount and update the status if found.


invoice number Debit status
12345 500rs
12345 100rs
12345 400rs
89765 100rs

Excel 2
invoice number Debit
12345 1000rs

invoice number Debit status
12345 500rs Found
12345 100rs
12345 400rs
89765 100rs

I need to do the sum of all debit amounts for invoice number 12345 in excel1, then search for same invoice number 12345 in excel2 and compare respective debit amount. if match found, then update status on excel1.

This is the overall project.
I used for each row in datatable to iterate through each record in excel, perform group by compare the debit amount with other excel.

please recheck the output sample as it differs from the description. In general, we can help with an alternate implementation

For a starter help have a look here: