0

In vb.net I have two datatables, dt1 and dt2. Both have only one column.

Now I need another table dt3 which should have the rows of dt1 that are not present in dt2.

I tried to do with LINQ:

Dim results = From table1 In dt1 
              Join table2 In dt2 On table1(0) Equals table2(0) 
              Select table1(0)  

But this returns only that are matching. But I need the opposite (rows not there in dt2).

Is it possible doing without LINQ?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Olivarsham
  • 1,701
  • 5
  • 25
  • 51
  • 1
    Earlier post explains how to do it in SQL: http://stackoverflow.com/questions/8165534/select-rows-not-in-another-table-sql-server-query – Germann Arlington Sep 12 '12 at 12:23
  • 1
    VB.net is **NOT** a database engine or interface, you use something else (like SQL) to connect to the database from VB.net You asked about doing it **WITHOUT** LINQ. I gave you the pointer to the answer. If you **DO** want to do it with LINQ try reading this too http://msdn.microsoft.com/en-us/library/bb386976.aspx – Germann Arlington Sep 12 '12 at 12:26

1 Answers1

1

As far as I understand, you don't need a join (as you are selecting only rows from the first table). You can use a LINQ query like

From table1 In dt1 _
Where Not (From table2 In dt2 Where table2(0) = table1(0)).Any() _
Select table1(0)
Devart
  • 119,203
  • 23
  • 166
  • 186