Exemple #1
0
        public static DataRow AppendColumns(DataRow dr, DataRow dr2, bool coalesce = true)
        {
            if (dr == null && dr2 == null)
            {
                return(null);
            }

            if (dr == null && dr2 != null)
            {
                return(MyUtils.CloneDataRow(dr2));
            }

            if (dr != null && dr2 == null)
            {
                return(MyUtils.CloneDataRow(dr));
            }

            DataRow drExtended = MyUtils.CloneDataRow(dr);

            foreach (DataColumn column2 in dr2.Table.Columns)
            {
                string columnName2  = column2.ColumnName;
                object columnValue2 = dr2[columnName2];
                if (drExtended.Table.Columns.Contains(columnName2))
                {
                    if (!MyUtils.IsEmpty(columnValue2) && MyUtils.IsEmpty(drExtended[columnName2]) && coalesce)
                    {
                        drExtended[columnName2] = columnValue2;
                    }
                }
                else
                {
                    drExtended[drExtended.Table.Columns.Add(columnName2, column2.DataType)] = columnValue2;
                }
            }

            return(drExtended);
        }