lance
lance

Reputation: 113

How to inner join two datatables in vb.net

Does anyone have an example of how to do an inner join on two datatables in vb.net? I have tried several examples that I found but I haven't gotten one to work thus far.

Upvotes: 1

Views: 6826

Answers (1)

Tim Schmelter
Tim Schmelter

Reputation: 460068

Your question is pretty vague, but maybe this helps anyway:

Dim both = From row1 In dataTable1.AsEnumerable()
           Join row2 In dataTable2.AsEnumerable()
           On row1.Field(Of String)("ColumnName") Equals row2.Field(Of String)("ColumnName")

For Each r1r2 In both
    Dim row1 = String.Format("{0}", String.Join(",", r1r2.row1.ItemArray))
    Dim row2 = String.Format("{0}", String.Join(",", r1r2.row2.ItemArray))
    Console.WriteLine(String.Format("{0} | {1}", row1, row2))
Next

Upvotes: 5

Related Questions