对两个数据集中的数据进行分组

发布于 2024-08-26 16:28:17 字数 832 浏览 5 评论 0原文

我的数据集有问题:

我有来自两个不同服务器的两个数据集,但它们具有相同的列。

所以就像这样:

第一个数据集:

asset description make jobtype jan feb ... dec
 0001  mine        ik     Acc   0   0       10
 0002  yours        ic    Over  0   0       10

第二个数据集:

asset description make jobtype jan feb ... dec
 0001  mine        ik     Acc   10   0       10
 0002  yours       ic     Gen   0    0       0

但我想将 2 个数据集合并为一个这样的数据集:

asset description make jobtype lhjan imjan lhfeb lhfeb ... lhdec imdec
 0001  mine        ik     Acc     0    10      0     0        10    10
 0002  yours       ic    Over     0     0      0     0        10     0

因此一个数据集的所有数据都与具有相同资产和相同作业类型的第二个数据集合并。

我尝试 linq 但我无法达到我想要的效果。 我正在研究 vb.net 框架 3.5。

你能帮我吗?

朱利安

i've got a problem with dataset:

I've got two dataset from two different server but they have the same columns.

so it's like that:

First DataSet :

asset description make jobtype jan feb ... dec
 0001  mine        ik     Acc   0   0       10
 0002  yours        ic    Over  0   0       10

Second dataset :

asset description make jobtype jan feb ... dec
 0001  mine        ik     Acc   10   0       10
 0002  yours       ic     Gen   0    0       0

But i would like to merge the 2 dataset into one like that:

asset description make jobtype lhjan imjan lhfeb lhfeb ... lhdec imdec
 0001  mine        ik     Acc     0    10      0     0        10    10
 0002  yours       ic    Over     0     0      0     0        10     0

so all the data from one is combine with the second with the same asset and the same jobtype.

I try linq but i can't arrive to make it like i want.
I'm working on vb.net framework 3.5.

could you help me?

Julien

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情栀口红 2024-09-02 16:28:17

如果您实际上只是想连接两者,则可以在 2 个不同的 Adaptor.fill() 中使用相同的数据集。

如果在第二次 FILL 之前不使用 NEW DATASET,则这两个数据集将被合并。

If you literally just want to join the two, you can use the same DATASET in 2 different Adaptor.fill().

If you do not use a NEW DATASET before the second FILL, the 2 will get merged.

╭⌒浅淡时光〆 2024-09-02 16:28:17

我只是想确保数据源 1 和 2 实际上是数据表。这就是我的回答将如何描述这一点。我也会用 C# 来描述它,尽管语法差别不大。您需要更改混合字段的选择。您还需要根据需要调整数据类型,

from dt1 in ds["datatable1"].AsEnumerable()
join dt2 in ds["datatable2"].AsEnumerable() on
new { asset = dt1.Field<string>("asset"), jobtype = dt1.Field<string>("jobtype") } equals
new { asset = dt2.Field<string>("asset"), jobtype = dt2.Field<string>("jobtype") }
select new
{
    asset = dt1.Field<string>("asset"),
    description = dt1.Field<string>("description"),
    make = dt1.Field<string>("make"),
    ...
    lhjan = dt1.Field<int>("jan"),
    imjan = dt2.Field<int>("jan"),
    lhfeb = dt1.Field<int>("feb"),
    imfeb = dt2.Field<int>("feb"),
    ....
};

这是近似 vb 语法:

Dim query = _
    From dt1 In dataset.Tables["datatable1"].AsEnumerable() _
    Join dt2 In dataset.Tables["datatable2"].AsEnumerable()_
        On  new { asset = dt1.Field(Of String)("asset"), jobtype = dt1.Field(Of String)("jobtype") } _
        Equals new { asset = dt2.Field(Of String)("asset"), jobtype = dt2.Field(Of String)("jobtype") } _
    Select New With _
        { _
            // see members from c# example _
        }

i just want to make sure that data sources 1 and 2 are actually data tables. this is how my answer will describe this. ill also be describing it in C#, though the syntax doesn't differ much. you need to alternate your selections for the intermingled fields. you'll also need to adjust your datatypes as necessary

from dt1 in ds["datatable1"].AsEnumerable()
join dt2 in ds["datatable2"].AsEnumerable() on
new { asset = dt1.Field<string>("asset"), jobtype = dt1.Field<string>("jobtype") } equals
new { asset = dt2.Field<string>("asset"), jobtype = dt2.Field<string>("jobtype") }
select new
{
    asset = dt1.Field<string>("asset"),
    description = dt1.Field<string>("description"),
    make = dt1.Field<string>("make"),
    ...
    lhjan = dt1.Field<int>("jan"),
    imjan = dt2.Field<int>("jan"),
    lhfeb = dt1.Field<int>("feb"),
    imfeb = dt2.Field<int>("feb"),
    ....
};

here is the approximate vb syntax:

Dim query = _
    From dt1 In dataset.Tables["datatable1"].AsEnumerable() _
    Join dt2 In dataset.Tables["datatable2"].AsEnumerable()_
        On  new { asset = dt1.Field(Of String)("asset"), jobtype = dt1.Field(Of String)("jobtype") } _
        Equals new { asset = dt2.Field(Of String)("asset"), jobtype = dt2.Field(Of String)("jobtype") } _
    Select New With _
        { _
            // see members from c# example _
        }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文