我有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