# Datatable update and merge

**URL:** <https://forum.uipath.com/t/datatable-update-and-merge/82148>\
**Category:** フォーラム\
**Created:** [December 13, 2018, 2:12pm UTC](https://forum.uipath.com/t/datatable-update-and-merge/82148 "2018-12-13T14:12:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![30ab42842da83aef823e](https://avatars.discourse-cdn.com/v4/letter/3/c5a1d2/32.png) [@30ab42842da83aef823e](https://forum.uipath.com/u/30ab42842da83aef823e)\
**Post date:** [December 13, 2018, 2:12pm UTC](https://forum.uipath.com/t/datatable-update-and-merge/82148/1 "2018-12-13T14:12:30Z")

</div>

初めまして。  
2つのexcelからデータテーブルを作りました。dt1,dt2としたら、  
dt1 には”ID"”Code"のColumnがあり、dt2には、”ID",”Code"、”name"があります。  
dt1が正しいデータを持っているデータテーブルなので、dt1を元に、dt2をupdateもしくはmergeしたいですが、私が使っているuipathにはjoin data table activityがありません。  
また、forumにある様々な方法で試してみましたが、エラーが発生し、失敗しました。

参考に、実現したいものをクエリーで作成してみました。  
急いでいるので、だれか助けてください。

＜参考＞  
Update dt2  
Set ID = (Select ID From dt1 where dt2.code=dt1.code

Insert  
Inset Into dt2 (ID,Code)  
Select ID,Code From dt1 where dt2.code != dt1.code

---

<div class="post-metadata">

**Author:** ![balupad14](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/balupad14/32/462142_2.png) [@balupad14](https://forum.uipath.com/u/balupad14)\
**Post date:** [December 13, 2018, 2:25pm UTC](https://forum.uipath.com/t/datatable-update-and-merge/82148/2 "2018-12-13T14:25:43Z")

</div>

Hi @30ab42842da83aef823e,

This will help you to fix you problem.

> **[Join Data Tables](https://docs.uipath.com/activities/docs/join-data-tables)**
>
> UiPath.Core.Activities.JoinDataTables Combines rows from two tables by using values common to each other, according to a Join rule, which is specified in the JoinType property. Properties Common DisplayName - The display name of the activity. Input...

> **[Merge Data Table](https://docs.uipath.com/activities/docs/merge-data-table)**
>
> UiPath.Core.Activities.MergeDataTable Merges the Destination with the Source, indicating whether to preserve changes and how to handle missing schema in the Source. Properties Common DisplayName - The display name of the activity. Input Destination -...

Make sure that you have the below version or higher.

[https://www.uipath.com/product/release-notes/uipath-v2018.3.1](https://www.uipath.com/product/release-notes/uipath-v2018.3.1)

Regards  
Balamurugan.S

---

<div class="post-metadata">

**Author:** ![30ab42842da83aef823e](https://avatars.discourse-cdn.com/v4/letter/3/c5a1d2/32.png) [@30ab42842da83aef823e](https://forum.uipath.com/u/30ab42842da83aef823e)\
**Post date:** [December 13, 2018, 2:29pm UTC](https://forum.uipath.com/t/datatable-update-and-merge/82148/3 "2018-12-13T14:29:26Z")

</div>

Hi, @balupad14 thank you so much for your reply,  
but I am not able to use the 2018.3 version.  
What could I do in this case?

---

<div class="post-metadata">

**Author:** ![balupad14](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/balupad14/32/462142_2.png) [@balupad14](https://forum.uipath.com/u/balupad14)\
**Post date:** [December 13, 2018, 2:31pm UTC](https://forum.uipath.com/t/datatable-update-and-merge/82148/4 "2018-12-13T14:31:19Z")

</div>

Hi @30ab42842da83aef823e,  
It may help you.

> [@Join Two DataTables](https://forum.uipath.com/t/join-two-datatables/87):
>
> Trevor Napier June 27, 2016 21:44 NONE So I know going through VB/C# you can use LINQ to join two tables IE Dim query = From tl1 In InputTableOne.AsEnumerable() \_ Join tl2 In InputTableTwo.AsEnumerable() \_ On tl1.Field(Of Integer)(“Customer\_ID”) Equals \_ tl2.Field(Of Integer)(“Customer\_ID”) \_ Select New With \_ { \_ .ID = tl1.Field(Of Integer)(“Customer\_ID”), \_ .Customer\_Name = tl1.Field(Of String)(“Customer\_Name”), \_ .Order\_ID = tl2.Field(Of Integer)(“Order\_ID”), \_ .Order\_Item = tl2.…

Regards  
Balamurugan.S

---

<div class="post-metadata">

**Author:** ![kyd\_has](https://avatars.discourse-cdn.com/v4/letter/k/73ab20/32.png) [@kyd\_has](https://forum.uipath.com/u/kyd_has)\
**Post date:** [December 14, 2018, 6:38am UTC](https://forum.uipath.com/t/datatable-update-and-merge/82148/5 "2018-12-14T06:38:48Z")

</div>

LINQでやるなら

result = From tl1 In dt1.AsEnumerable \_ From tl2 In dt2.AsEnumerable.Where(Function(m) m.Field(Of String)("code") = tl1.Field(Of String)("code")).DefaultIfEmpty() \_ Select New With \_ { \_ .id = tl1!id, \_ .code = tl1!code, \_ .name = If(tl2 Is Nothing, "", tl2!name) \_ }

で大丈夫だと思いますが、結果がIEnumerableになってしまいます。  
※結果をどう使いたいか次第ですが、結果をループで処理するならこれでもよいのですが。。

ここは泥臭いかもしれませんが、ループで処理した方がメンテするのも楽かと思います。  
※私ならそうします。

> [@Excel串刺し計算](https://forum.uipath.com/t/excel/79580):
>
> fourmで以前教えて頂いたexcel串刺し計算に関してです。 複数のファイルの読み込み各cellを足し算していくものです。 WFは、 1 計算対象となるexcelを指定フォルダに保存 2 assign :指定フォルダからファイルを読み込む targetlFiles = IO.Directory.GetFiles(VpathName + VSubPath, “\*.xlsx”) targetlFilesの型はstring 3 for each でexcelファイルを1件ずつ読む 4 excel appliationで順番に読む 5 for eachでシートを読む for each sheetname in WB02.GetSheets() 6 この後の処理は 5列31行のデータ合計151回 read cell でシート名とcellを指定 null値の確認 if String.IsNullOrEmpty(vc03) or String.IsNullOrWhiteSpace(vc03) else assgin VC03\_int = Decimal.Pars…

が参考になるのでは。
