Help with this code

Hello,

I have this code I use in an invoke code to matching entries by using two specific columns from two different datatables.
This gets the Matching values in Table A

Dim ex As Exception
Try
dtjoin = dtMain.AsEnumerable().Where(Function(row) dtRepsonseCodeZero.AsEnumerable().Any(Function(x) x(“PAYMENT_REFERENCE”).ToString=row(“NARRATION”).ToString)).CopyToDatatable
errorMessage = ex.Message
Catch ex
errorMessage = ex.Message
End Try


and this gets non matching values in Table A

Dim ex As Exception
Try
dtLeftOver = dtMain.AsEnumerable().Where(Function(row) Not dtRepsonseCodeZero.AsEnumerable().Any(Function(x) x(“PAYMENT_REFERENCE”).ToString=row(“EXTERNAL_REF_NO”).ToString)).CopyToDatatable
Catch ex
errorMessage = ex.Message
End Try

Now my issue is that the code is taking forever to run now because the records in both tables are much now.
Please how do i fix this or any alternative
Thanks a lot

@MasterOfLogic Do you have to use Invoke Code ? Have you tried just by using Assign Activities ?

@supermanPunch oh yeah I tried the assign too… it still takes forever

@MasterOfLogic I’m confused a bit by your code, and I would definitely recommend using an assign activity rather than invoke code, as invoke code can slow things down in my experience.

The top activity is just trying to join the datatables dtMain and dtRepsonseCodeZero on “PAYMENT_REFERENCE” = “NARRATION”, is that correct? If so, why not just use the join datatable activity?

The bottom code is trying to get all the rows from the 2 datatables EXCEPT the ones where “PAYMENT_REFERENCE” = “NARRATION”, is that correct? You can use an EXCEPT statement in linq to achieve this

@ppr is always quite helpful in all things linq related, so hopefully he’ll come in and give some tips if you’re still having trouble :slight_smile:

1 Like

@MasterOfLogic What’s the total number of rows in both the datatables ?

@MasterOfLogic
just share same data samples and a description with us. based on this we can help on finding the matching / non matching rows from the diffeent datatables

heres what i am trying to achieve …although i think i have just achieved it using join datatable , but i did love to see the linq method…My interest is in dt1 and i am using the column car to compare . @ppr @Dave

If performance is needed, dont use linq at all… The first thing to think here is where you get your data from, if it is database, do those joins in there instead, if not possible, than use straight datatable manipulation without all conversions linq expression will do with those commands…

1 Like

@bcorrea Thanks a lot. I get you . So i used a join data table now and filtered activities. I think it works fine now . Thats true. Thanks a lot

1 Like

Find starter Help here:
Find_Common_NonCommon2_By1Col.xaml (13.4 KB)

But this scenario also can perfect be done with Join Datatable activity.
Find starter help here:
Match-NonMatch_2Col_2ResultTabs_JoinActivity.xaml (18.2 KB)