私は2つのテーブルを持っています:
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行すべてを含むテーブルを提供しています。