Wednesday, April 20, 2011

DataTable Intersection Operation

I have two datatables defined like this;

Dim db1, db2 As New DataTable

db1 and db2 hold results from different queries but the columns in both are exactly the same. I would like to create another datatable which consists of records that are in both db1 and db2. i.e I want the intersection of the two datatables. Is there an easy way to do this?

(The resultant datatable will be used to populate a gridview.)

From stackoverflow
  • If you are using VB.NET with LINQ you could do it like this:

    Dim db3 = db1.Intersect(db2)
    

    From there just use db3 to populate your GridView.

0 comments:

Post a Comment