复制到Datatable [英] Copy to Datatable

查看:86
本文介绍了复制到Datatable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在加入数据表以创建一个新的数据表,

I am joining datatables to create a new datatable,

代码:

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);

在上述代码中,

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

对于数十万行来说很慢。我想将的数据放入 dt

is slow for hundreds of thousands of rows. I want to put the data of row into dt

我想知道是否有任何方式存在,所以我不必使用循环创建一个新的datatable?

I want to know if there is any way exists so, that I don't have to use loop to create a new datatable ?

推荐答案

由于@Thanos Markow提到,您需要使用 dataTable.Merge(第二个数据表)

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

重要说明:合并操作仅考虑原始表和要合并的表。儿童桌不受影响或包括。如果一个表有一个或多个子表,定义为关系的一部分,则每个子表必须单独合并。

An Important Note: The merge operation takes into account only the original table, and the table to be merged. Child tables are not affected or included. If a table has one or more child tables, defined as part of a relationship, each child table must be merged individually.

这篇关于复制到Datatable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆