We help IT Professionals succeed at work.
Get Started

Build dynamic LINQ Query over Datatables

Last Modified: 2013-11-11
Below is LINQ query which returns the New records which exist in dtFreshdata  but not in dtSnapShot.
My question is that
how to generalize this code so that it works for all DataTables of different schema
In this query I hard coded column name but I want to construct it dynamically.
and I have more than one Constraint column and i want Group join ON more than one constraints.

for e.g string[] strArrConstraints contains the constraints.

I hope You people come out with a solution ASAP.
Dim objquery = From FreshData In dtFreshData.AsEnumerable() _
                           Group Join SnapShotData In dtSnapShot.AsEnumerable() _
                 On FreshData("ACCTID") Equals SnapShotData("ACCTID") Into HaveMatch = Any() _
            Where Not HaveMatch _
            Select ACCTID = FreshData("ACCTID"), ACCTNAME = FreshData("ACCTNAME"), ACCTADDRESS = FreshData("ACCTADDRESS")

Open in new window

Watch Question
This problem has been solved!
Unlock 1 Answer and 14 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