我有2個數據表,我不知道它們的數據列表。該列表必須在運行時提取,並用於完整外連接。在2個數據表上使用列表的全外連接
使用這些列時,兩個表之間的列需要合併,我需要顯示所有數據。
直到現在我在做什麼是
- 獲取公共列,使用相交,並執行的IEqualityComparer
- 創建一個新的數據表,這些列,從而使2個數據表將被合併到這個新表
但是,我在第二步中遇到了Linq問題。
到目前爲止我有:
獲取公共列
// Get common columns var commonColumns = dt1.Columns.OfType().Intersect(dt2.Columns.OfType(), new DataColumnComparer());
創建新的數據表
// Create the result which is going to be sent to the user DataTable result = new DataTable(); // Add all the columns from both tables result.Columns.AddRange( dt1.Columns.OfType() .Union(dt2.Columns.OfType(), new DataColumnComparer()) .Select(c => new DataColumn(c.Caption, c.DataType, c.Expression, c.ColumnMapping)).ToArray());
我怎樣才能獲得有效的全外動態加入,從在運行時提取的datacolumns列表?
像魅力一樣工作 - 歡呼馬特! – Mez