我有兩個表:LINQ的更新和合並兩個結果集(從數據表)
Customer:
+------------------------------+
| ID | Address |
|------------------------------|
| 1 | London, UK |
| 2 | Paris, France |
+------------------------------+
Updated Customer:
+------------------------------+
| ID | Address |
|------------------------------|
| 1 | Birmingham, UK |
+------------------------------+
如何合併表,得到這樣的結果? :
Customer:
+------------------------------+
| ID | Address |
|------------------------------|
| 1 | Birmingham, UK |
| 2 | Paris, France |
+------------------------------+
C#/ LINQ的代碼,我試圖與工會:
DataTable customer = new DataTable();
customer.Columns.Add("ID", typeof(int));
customer.Columns.Add("Address", typeof(string));
DataTable updatedCustomer = new DataTable();
updatedCustomer.Columns.Add("ID", typeof(int));
updatedCustomer.Columns.Add("Address", typeof(string));
customer.Rows.Add(1, "London, UK");
customer.Rows.Add(2, "Paris, France");
updatedCustomer.Rows.Add(1, "Birmingham, UK");
var cust = from row in customer.AsEnumerable()
select new
{
ID = row[0],
Address = row[1]
};
var uCust = from row in updatedCustomer.AsEnumerable()
select new
{
ID = row[0],
Address = row[1]
};
var updatedTable = cust.Union(uCust);
//Please use cust and uCust objects, not customer and UpdatedCustomer.
聯盟給了我一個表與所有3行,但是。
'datatable.Merge'? –