Merge two DataTables with LINQ
My question is similar too THIS
I have two DataTables:
DataTable 1:
Column 1: Date
Column 2: Requests 1
DataTable 2:
Column 1: Date
Column 2: Requests 2
I need the bellow result:
New DataTable:
Column 1: Date
Column 2: Requests 1
Column 3: Requests 2
Expected Result:
Date Requests 1 Requests 2 Total
15/08/2013 25 40 60
14/08/2013 40 60 100
13/08/2013 40 0 25
12/08/2013 0 80 80
What I did until now:
DataTable Lista_1 = ds.Tables[0];
DataTable Lista_2 = ds.Tables[1];
var myLINQ = from l1 in Lista_1.AsEnumerable()
join l2 in Lista_2.AsEnumerable() on
l1.Field<DateTime>("Data") equals
l2.Field<DateTime>("Dia")
select new
{
dataRelatorio =
l1.Field<DateTime>("Data"),
acessoRelatorio =
l1.Field<int>("Total"),
camerasRelatorio =
l2.Field<int>("contagem"),
totalRelatorio =
l1.Field<int>("Total") +
l2.Field<int>("contagem")
};
And I would like to return an IList (System.Collections.IList)
No comments:
Post a Comment