This is a modified version of solution 2 with two examples, the first uses Linq
fluent syntax and the second uses query syntax.
private static void Main(string[] args)
{
var dt1 = new DataTable();
dt1.Columns.Add("ID", typeof(long));
dt1.Columns.Add("COD", typeof(int));
dt1.Columns.Add("No", typeof(int));
dt1.Columns.Add("letter", typeof(string));
dt1.Rows.Add(83, 65, 0, "abc");
dt1.Rows.Add(21, 28, 0, "abc");
dt1.Rows.Add(12, 32, 3, "asd");
dt1.Rows.Add(12, 55, 88, "asd");
var dt2 = new DataTable();
dt2.Columns.Add("ID", typeof(long));
dt2.Columns.Add("DETAIL", typeof(string));
dt2.Rows.Add(15, 33);
dt2.Rows.Add(21, 2);
dt2.Rows.Add(12, 3);
DataTable dtTemp = dt1.Clone();
dtTemp.Columns.Add("DETAIL");
DataTable resultDataTable =
dt1.AsEnumerable()
.Join(
dt2.AsEnumerable(),
f => f.Field<long>("ID"),
s => s.Field<long>("ID"),
(f, s) => new { f, s })
.Select(
a =>
dtTemp.LoadDataRow(
new object[]
{
a.f.Field<long>("ID"),
a.f.Field<int>("COD"),
a.f.Field<int>("No"),
a.f.Field<string>("letter"),
a.s.Field<string>("DETAIL")
},
false))
.CopyToDataTable();
DataTable resultDataTable2 = (from dataRows1 in dt1.AsEnumerable()
join dataRows2 in dt2.AsEnumerable()
on dataRows1.Field<long>("ID") equals dataRows2.Field<long>("ID")
select
dtTemp.LoadDataRow(
new object[]
{
dataRows1.Field<long>("ID"),
dataRows1.Field<int>("COD"),
dataRows1.Field<int>("No"),
dataRows1.Field<string>("letter"),
dataRows2.Field<string>("DETAIL")
},
false)).CopyToDataTable();
}