Copy to Datatable

I am connecting datatables to create a new datatable,

Code:

var row = from r0w1 in dt_vi.AsEnumerable()
              join r0w2 in dt_w.AsEnumerable()
              on r0w1.Field<int>("ID") equals r0w2.Field<int>("iD")
              join r0w3 in dt_re.AsEnumerable()
              on r0w1.Field<int?>("ID") equals r0w3.Field<int?>("id")
              join r0w4 in dt_def.AsEnumerable()
              on r0w1.Field<int?>("ID") equals r0w4.Field<int?>("id") into ps
              from r0w4 in ps.DefaultIfEmpty()
              select r0w1.ItemArray.Concat(r0w2.ItemArray.Concat(r0w3.ItemArray.Concat(r0w4 != null ? r0w4.ItemArray : new object[] { }))).ToArray();


foreach (object[] values in row)
    dt.Rows.Add(values);

In the above code

foreach (object[] values in row)
    dt.Rows.Add(values);

slower for hundreds of thousands of lines. I want to put data rowindt

I want to know if there is any way, so I do not need to use a loop to create a new datatable?

0
source share
1 answer

As @Thanos Markow pointed out, you need to use dataTable.Merge(the second data table).

: . . , , .

+1

Source: https://habr.com/ru/post/1620720/


All Articles