Farhan Shariff

Farhan Shariff

  • NA
  • 933
  • 238.2k

Compare 2 datatable columns and delete missing columns

Jun 5 2014 9:07 AM
I have two datatables 

Table7_ref
A
B
C
D
E
F
G
H
I
J
1
2
3
4
6
8
9
0
-
8




Table7
A
B
C
D
13
11
144
12

Output
table7_ref
A
B
C
D
1
2
3
4


What is the mistake I am doing

for(int p=0; p<table7_ref.Columns.Count; p++)
            {
                string colxname = table7_ref.Columns[p].ToString();
                if (!table7.Columns.Contains(colxname))
                {
                    table7_ref.Columns.Remove(colxname);
                }
            }

Answers (8)