I have two tables in which two columns are fixed. Some columns are identical, and some are new. The columns are dynamic.
I need to do this at the code level, and I'm trying to execute a loop and conditions
I want to create a report after the condition,
- All columns in table1 and table2 must be present.
- If the column is common and there is a value, it should be added with the same row in another table.
- If a row is present in one table but not in another, it should be included.
Data examples
Table 1
ID | NAME | P1 | P2 | P3
----------------------------
1 | A1 | 1 | 2 | 3.3
2 | A2 | 4.4 | 5 | 6
TABLE 2
ID | NAME | P1 | P2 | P4
---------------------------
1 | A1 | 10 | 11 | 12
2 | A2 | 12 | 14 | 15
3 | A3 | 16 | 17 | 18
Expected Result:
ID | NAME | P1 | P2 | P3 | P4
---------------------------------
1 | A1 | 11 | 13 | 3.3 | 12
2 | A2 | 16.4 | 19 | 6 | 15
3 | A3 | 16 | 17 | null| 18
Progress so far:
First, I combined these two tables into table1
table1.Merge(table2)
Then, trying to group by it
var query = from row in table1.AsEnumerable()
group row by new
{
ID = row.Field<int>("ID"),
Name = row.Field<string>("Name")
}
into grp
select new
{
ID = grp.Key.ID,
Name = grp.Key.Name,
Phase1 = grp.Sum(r => r.Field<decimal>("P1"))
};
, datatable. . cs.
, , , , .
?
. . .
.
:
http://dl.dropbox.com/u/26252340/Program.cs