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 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
@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…