1

i want to compare the two data table columns and find duplicates

for example

dataTable1
autoid ponbr polinenbr quantity
1 0001 10 5
2 0002 12 6
3 0003 15 7

dataTable2
autoid ponbr polinenbr quantity
1 0001 10 5
2 0002 15 7
3 0003 12 9

in the above two dataTable i would like to compare the ponbr and polinenbr column and find the duplicates and get the autoid..

how to do it in vb.net

thanks in advance..

Prabhakaran
  • 92
  • 2
  • 10

2 Answers2

1

Create 2 Loops

Foreach (DataRow row1 In dataTable1)
{
   Foreach (DataRow row2 In dataTable2)
   {
       if (row1[1] == [row2[1])
       {
         // means ponbr matched
         // do your stuff
         return row2[0];   //returns the autoid from datatable2 
       }
       if (row1[2] == [row2[2])
       {
         // means polinenbr matched
         // do your stuff
         return row2[0];  //returns the autoid from datatable2
       }

   } 
} 

im sorry if this is in C# i dont have VB installed in my VS and i cant write them without IDE because i was focusing on my C# and forgot my VB skills.

But i hope this would still be useful for you

Philip Badilla
  • 1,038
  • 1
  • 10
  • 21
0

Can you check these answers ?

here you can join the table with another, similar the way SQL join works\ Just have a try on this.

How To: Use DataRelation to perform a join on two DataTables in a DataSet?

Inner join of DataTables in C#

Community
  • 1
  • 1
kbvishnu
  • 14,760
  • 19
  • 71
  • 101