Farhan Shariff

Farhan Shariff

  • NA
  • 933
  • 242.2k

Compare DataTable and show rows that are not present

Mar 17 2014 6:45 AM
table1
|
Par Name.........| Par #|.......Units |LSL  |  USL | -----SKIP

|
Diffusion.........908513100.......-... .. 0  -----99.9  -----1

Program...........908514100.......-...  99.5--- 999   -----1

AC_IC .. . . . . .908512100. . . . . . . .14-------13---------1

ACX_IC. . . . . . .98212100.. . . . . .  1 ------62----------1


table2
starttime   
| Product   | Device   | Diffusion   | Program |

11/7/2013  SAF5100EL   163   -0.145712003   -0.146583006 

11/7/2013  SAF5100EL   84   -0.137499005   -0.137592003

11/7/2013  SAF5100EL   44   -0.142690003   -0.143250003 

11/7/2013  SAF5100EL   164   -0.139434993   -0.140459001

11/7/2013  SAF5100EL   34   -0.147183999   -0.148519993  


table3  

|Diffusion|   | Program |

-0.145712003   -0.146583006

-0.137499005   -0.137592003

-0.142690003   -0.143250003

-0.139434993   -0.140459001

-0.147183999   -0.148519993

//dt1 contains Diffusion etc as rows
//dt2 contains diffusion etc as columns
//dt3 is the required table

table1 and table2 are compared and all parameter names present in
table 1[row] and also 
in table2[column] are copied to table 3.
Now i want to display Par names which are present table1
and not in table2[ie 
AC_IC ACX_IC]
how to include statements to show those parameter names


DataTabl DataTe dt3 = newable();
DataRow dr = null;
for (int i = 0; i < dt1.Rows.Count; i++)
{
       string col = dt1.Rows[i]["Par Name"].ToString();
    if (dt2.Columns.Contains(col))
   {
       if (!dt3.Columns.Contains(col))
          {
            dt3.Columns.Add(col, typeof(string));
          }
       if (dt3.Rows.Count == 0)
          {
             for (int j = 0; j < dt2.Rows.Count; j++)
         {
            dr = dt3.
NewRow();
            dt3.Rows.Add(dr);
           }
           }
     for (int j = 0; j < dt2.Rows.Count; j++)
    {
       dt3.Rows[j][col] = dt2.Rows[j][col].ToString();
     }
 
}


}




Answers (8)