Ali
Ali

Reputation: 684

Merging DataTables in vb.net

I use vb.net to develop and I've used 5 DataTables in a windows application form and I need to combine these 5 DataTables together base on a primary key field.

To clarify

DataTable1 (PK,f1,f2,f3)
DataTable2 (PK,f4,f5,f6)
DataTable3 (PK,f7)
DataTable4 (PK,f8)
DataTable5 (PK,f9)

I need to have :

DataTable (pk,f1,f2,f3,f4,f5,f6,f7,f8,f9 )

Upvotes: 0

Views: 1624

Answers (1)

Matt Wilko
Matt Wilko

Reputation: 27342

Add a reference to System.Data.DataSetExtensions to your project,

Then you can perform a UNION on the tables like this:

    Dim dt As DataTable
    Dim dt2 As DataTable

    Dim result = dt.AsEnumerable().Union(dt2.AsEnumerable())

Upvotes: 1

Related Questions