15,958,091 members
See more:
I have two DataTables. if both the datatables having the same value, Then mark X in both columns, If there is difference then mark the column with highest value with X.

```Datatable1

SI.No       Name      Weight
1       Ship       500

2       Train      600

3       Plane      700

4       Car        800
```

```Datatable2

SI.No        Name         Weight

1          Ship          500

2          Train         400

3          Plane         800

4          Car           200```

want the result to be:

Datatable3

```SI.No Name    Weight          Datatable1        Datatable2

1   Ship      500              X                 X

2   Train     600              X

3   Plane     700                                X

4   Car       800              X
```

I have tried the below:-

C#
```DataTable Datatable3 = (from a in Datatable1.AsEnumerable()
join b in Datatable2.AsEnumerable()
on a["Name"].ToString() equals b["Name"].ToString()
a["Weight"].ToString() equals b["Weight"].ToString() into g
where g.Count() != 1 select a).CopyToDataTable();
dataGrid1.ItemsSource = Datatable3.DefaultView;
```
Posted
Updated 22-Dec-14 18:59pm
v6
Maciej Los 29-Dec-14 11:24am

## Solution 1

Maciej Los 29-Dec-14 11:26am
Ha, ha, ha... :laugh:
You showed Him/Her solution to His/Her question on SO ;)
+5!
ridoy 29-Dec-14 12:00pm
yes, he posted same question in CP and SO for multiple times, :p

## Solution 2

sample code:
C#
```void Main()
{
var dataTable1 = GetTable1();
var dataTable2 = GetTable2();
var resultingTable = from t1 in dataTable1.AsEnumerable()
join t2 in dataTable2.AsEnumerable()
on t1.Field<int>("No") equals t2.Field<int>("No")
select new { t1, t2 };

var newDataTable =GetTable3();
foreach(var dr in resultingTable)
{
var weight1 = dr.t1.Field<int>("Weight");
var weight2 = dr.t2.Field<int>("Weight");
DataRow newRow = newDataTable.NewRow();
newRow["No"] =dr.t1.Field<int>("No");
newRow["Name"] =dr.t1.Field<string>("Name");
newRow["Weight"] = weight1;
newRow["Table1"] = weight1==weight2?"X": weight1>weight2?"X":"";
newRow["Table2"] = weight2==weight1?"X": weight2>weight1?"X":"";

}

}

DataTable GetTable1()
{
// Here we create a DataTable with four columns.
DataTable table = new DataTable();

// Here we add five DataRows.

return table;
}

DataTable GetTable2()
{
DataTable table = new DataTable();

return table;
}
DataTable GetTable3()
{
// Here we create a DataTable with four columns.
DataTable table = new DataTable();
return table;
}```

v2
LAKSHMINARAYANAN E 6-Jan-15 2:53am
Why you have used "newDataTable.Dump();" . Whether it is a Object or method. Error!
DamithSL 6-Jan-15 3:50am
Remove that line, copied from linqpad[^] but forgot to remove that line