0

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 )
2
  • I used DataTable.Merge but this adds additional rows for second table. it does not match the ids and maintains the row count Commented Nov 1, 2013 at 3:38
  • You should look into using a Dataset, then join all of the tables on the primary key when you select. I think you can do this with a Dataview, though I've only used that class on a single table. Commented Nov 1, 2013 at 7:39

1 Answer 1

1

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())
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.