Optimize code to perform for larger records

Hi Devs, please assist as I am still stuck at this for some time, this particular code works fine for smaller records but for larger records say 400000 it takes lots of hours to process. Please what can be done to optimize this to run at lower time.Pls I believe you can assist.Regards
Try
If dtCr IsNot Nothing And dtDr IsNot Nothing Then
For Each row As DataRow In dtCr.Rows
Dim N As String = row.Item(“N”).ToString
Dim amt As Double = CDbl(row.Item(“AMOUNT”).ToString)
For Each row1 As DataRow In dtDr.Rows
Dim N1 As String = row1.Item(“N”).ToString
Dim amt1 As Double = (CDbl(row1.Item(“AMOUNT”).ToString))
Dim drCr As String = row1.Item(“DRCR”).ToString
If N.Contains(N1) AndAlso amt = amt1
row1.SetField(“Check”,“UnMatch”)
'Console.WriteLine(“UnMatched”)
Else If N.Contains(N1) AndAlso amt = Math.Abs(amt1) AndAlso drCr = “D”
row1.SetField(“Check”,“DebitMatch”)
'Console.WriteLine(“DebitMatched”)
End If
'End If
Next
Next
End If
Catch Ex As Exception
Console.WriteLine(Ex.Message)
End Try

Hi @RPA-botDev,

Can you share the .xaml containing your code.

Regards,
MY

Hello @RPA-botDev

As you are executing this process for a large number of rows , the for loop need to execute one by one and it will take time for the completion.

How much time its taking for the completion??? Also could you please share the screenshot of the excel and the requirement which you are trying to do.

It’s taking more than 2hrs to run, so I have to 2 datatables and I want to check if row(“N”) values in dtCr is contained/equal in row(“N”) dtDr and also row(“Amount”) in dtCr equal to row(“Amount”) in dtDr if true update row(“Check”) to “UnMatch” in dtDr. Hope it’s clearer pls

Check out expected output from the 2 dt
checkpp.xlsx (10.5 KB)

@RPA-botDev Did you checked the feasibility of using Left Join . USing that you can identify the matching rows. DT1 left join DT2

Then make a loop with that new datatable and update the values.

1 Like

I will test now @Rahul_Unnikrishnan