We help IT Professionals succeed at work.
Get Started

Linq Syntax - Find Duplicates

498 Views
Last Modified: 2016-02-15
I am writing a class in a VB.NET project which will compare data between two data sources.

I have two datatables (tblSource and tblDest)

I am looking for a generic 'Find Duplicates' Linq statement where I DO NOT KNOW the Key Columns at design time.

For example, the following will work if I know the table is going to have Columns called CusOrderID and CusOrderStore:

Dim duplicates = tblDest.AsEnumerable().GroupBy(Function(r) New With { _
                            Key .CusOrderID = r.Item("CusOrderID"), _
                            Key .CusOrderStore = r.Item("CusOrderStore") _
                        }).Where(Function(gr) gr.Count() > 1).[Select](Function(g) g.Key)

Open in new window

But seeing at this is a generic class, I will not know these column names.

I would like help with amending the statement above to run off a DataColumn array variable instead. If that is possible.

Regards,

Rawden.
Comment
Watch Question
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant

An Experts Exchange subscription includes unlimited access to online courses.

Get Started
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE