Code taking long time to execute

Hi All,

I have a code which I use to remove already processed records from the new records. But with time as the processed record count is increasing it is becoming slow in processing. I am using the below code for your reference ,
completeDataIvosDT.AsEnumerable().Where(Function(row) Not processedDataDT.AsEnumerable().
Select(Function(r) r.Field(Of String)(“Claim Number”)).Any(Function(x) x = row.Field(Of String)(“Claim Number”))).

Need your suggestions how to make it fast because right now 40k data is there it takes 25 mins to run this. Please help.

@Yoichi any suggestions on how to split these and do something.

Hi @Ritika_Singh ,

Could you maybe try by creating the prepared data for the comparison ? As it seems from the code you are trying to compare only one column from the other datatable.

We could get the Data prepared for that and stored it an array or a list, then perform the comparison on the list prepared. This way we should be able to reduce some time in Always iterating through the datatable and grabbing the values again.

claimNumbers = processedDataDT.AsEnumerable().Select(Function(r) r("Claim Number").ToString.Trim).ToArray

Here, claimNumbers is a variable of type Array of String

Next, we can use this array in the same way in the Linq that you have mentioned.

completeDataIvosDT.AsEnumerable().Where(Function(row) Not claimNumbers.Any(Function(x) x.Equals(row("Claim Number").ToString.Trim))).CopyToDataTable()

Let us know if this reduces the time for execution.

Also Check the below post for handling errors on Direct conversion to Datatable.

Have a look here for optimization analysis steps