Full outer join, on 2 data tables, with a list of columns

后端 未结 3 476
孤独总比滥情好
孤独总比滥情好 2021-01-05 04:01

I have 2 data tables, which I do not know their list of data columns. This list must be extracted at run time, and be used for the full outer join.

When using these

3条回答
  •  感动是毒
    2021-01-05 04:30

    This might work for you

    var commonColumns = dt1.Columns.OfType().Intersect(dt2.Columns.OfType(), new DataColumnComparer());
            DataTable result = new DataTable();
    
            dt1.PrimaryKey = commonColumns.ToArray();
    
            result.Merge(dt1, false, MissingSchemaAction.AddWithKey);
            result.Merge(dt2, false, MissingSchemaAction.AddWithKey);
    

提交回复
热议问题