UiPath Datatable PrimaryKeyを設定してVLOOKUP関数のように検索する

主キー(PrimaryKey)とは?

DataTableには主キーと呼ばれる重複のない列、軸となる列を設定することができます。イメージとしては「No」といった連番の数字、もしくは簡単なテーブルなら「氏名」など。もしくは氏名は重複が存在する可能性があるので「電話番号」などが主キーとなる可能性もあります。

サンプルとして、以下のようなDatatableが存在するとします。

このDataTableの列「電話番号」を主キーとして、電話番号に紐づく列「氏名」を出力したい場合、どうすればいいでしょうか?イメージとしてはExcelのVLOOKUP関数で電話番号を元に氏名を参照する感覚です。それではやってみましょう。

DataTableに主キーを設定

まず上記画像のようなアクティビティ「データテーブルを構築」で顧客名簿のようなDataTable型「Dt」を出力します。その後にAssignアクティビティでDtに主キーを設定しましょう。


詳細のコードは以下の通りです。

'---左辺
DataTable型.PrimaryKey
'---右辺
New DataColumn(){DataTable型.Columns.Item("電話番号")}

何が起こっているのかローカルパネルを見てみる

PrimaryKey(主キー)?PrimaryKeyについてイメージが追い付いていない方もいらっしゃると思いますので、ここで一度デバッグをしてみましょう。
この画像はまだPrimaryKeyを(主キー)を設定していない画面です。ローカルパネルのPrimaryKeyを見てみると、DataColumn[0]{} つまり何も存在しないことが示されています。

ここでもう一歩ステップインして主キーを代入してみましょう。
するとPrimaryKeyの中に値DataColumn[1]{[電話番号]}が記載されているのがわかります。

このようにDataTable型変数には様々な要素が含まれています。DataTable.Columnsと記載すれば列関連、DataTable.Rowsと記載すれば行関連の要素が出力されます。それと同じようにDataTable.PrimaryKeyという要素に詳細を記載した、ということです。

Findを使ってDataTableからVLOOKUPのように検索する

では次にFindを使ってDataTalbeから要素を検索してみましょう。
はじめに、DataTableから電話番号「0761101503」を検索し、列「氏名」を出力してみたいと思います。期待値としては「岡田常男」が出力されます。

まず変数「電話番号」作成し、検索したい電話番号を設定します。今回は”0761101503”を設定してみましょう。

代入アクティビティの詳細は以下になります。

'---左辺
氏名

'---右辺
Dt.Rows.Find(電話番号).Item("氏名").ToString
Dt.Rows.Find("PrimaryKey列から検索したい文字列").Item("参照先の列名").ToString

最後にデバッグをして通してみましょう。1行書き込みに変数「氏名」が出力されれば成功です。

UiPath DataTable PrimaryKey 概要

無事に出力されました。

UiPath DataTable PrimaryKey 出力結果

367件のフィードバック

  1. Attractive section of content. I just stumbled upon your web
    site and in accession capital to assert that I get actually
    enjoyed account your blog posts. Any way I’ll be subscribing to your
    feeds and even I achievement you access consistently
    rapidly.

    Also visit my web blog: vpn special coupon

  2. world pharmacy india [url=http://indianpharm24.pro/#]Indian pharmacy international shipping[/url] reputable indian pharmacies

  3. pharmacy website india [url=http://indianpharm24.pro/#]Pharmacies in India that ship to USA[/url] india pharmacy mail order

  4. п»їlegitimate online pharmacies india [url=http://indianpharm24.pro/#]indian pharmacy purchase online[/url] india online pharmacy

  5. Howdy! Do you know if they make any plugins to help with Search Engine Optimization? I’m trying to get my
    blog to rank for some targeted keywords but I’m not seeing very good success.
    If you know of any please share. Thank you! I
    saw similar blog here: Eco product

  6. Hi there, You’ve done a fantastic job. I’ll definitely digg it and in my opinion suggest to my friends. I’m confident they will be benefited from this web site.

  7. I’m really enjoying thе design and layoսtof your bⅼog. It’s a very easy on the eyes which makes it muсh more enjoyablefor me to cօme here and visit more often. Did үouhire out a developer to cгeate your theme? Outstanding work!

  8. It’s impressive that you are getting ideas from this piece of writing as well as fromour discussion made at this time.my blog ซื้อหวยออนไลน์

  9. ขณะนี้บางครั้งอาจจะไม่มีผู้ใดไม่รุ้จะสล็อตออนไลน์ เนื่องมาจากเป็นเกมที่ใครๆพึงใจเพราะเหตุว่าเป็นเกมที่สร้างกำไรได้อย่างใหญ่โต UFABET เว็บสล็อตออนไลน์ยักษ์ใหญ่ จ่ายจริง จัดหนัก โบนัสมากมาย คิดจะเล่นสล็อตจึงควรไม่พลาด UFABET ขอรับ

  10. Howdy! Do you know if they make any plugins to helpwith SEO? I’m trying to get my blog to rank for some targeted keywords but I’m notseeing very good results. If you know of any please share.Cheers!

  11. What’s Taking place i am new to this, I stumbled upon this I’ve found It absolutely useful and it has aided me out loads. I am hoping to give a contribution & help different users like its helped me. Great job.

  12. An intriguing discussion is definitely worth comment. I believe that you need to publish more about this topic, it might not be a taboo matter but generally people do not speak about these subjects. To the next! Many thanks!!

  13. Thanks for every other informative blog.The place else may I am getting that type of info written in such an ideal approach?I’ve a mission that I am just now running on, andI have been at the look out for such info.

  14. online pharmacy delivery usa [url=https://familypharmacy.company/#]no prescription needed canadian pharmacy[/url] Cheapest online pharmacy

  15. Hey There. I discovered your blog using msn. That is an extremely smartly written article. I will be sure to bookmark it and return to learn more of your helpful information. Thank you for the post. I’ll certainly return.

  16. you are actually a excellent webmaster. The web site loading pace is incredible. It kind of feels that you are doing any distinctive trick. Moreover, The contents are masterwork. you’ve performed a magnificent task on this subject!

  17. I am not sure where you are getting your info, but good topic. I needs to spend some time learning more or understanding more. Thanks for excellent info I was looking for this information for my mission.

  18. In the great pattern of things you’ll get an A+ just for effort. Where exactly you lost everybody was on your facts. You know, as the maxim goes, details make or break the argument.. And that could not be much more true here. Having said that, allow me inform you just what did give good results. Your article (parts of it) is definitely highly engaging and that is possibly the reason why I am making the effort in order to opine. I do not really make it a regular habit of doing that. 2nd, although I can certainly notice the leaps in reason you come up with, I am not really sure of exactly how you seem to connect your points that produce the actual final result. For right now I will yield to your issue but wish in the near future you connect your facts much better.

  19. I am just writing to make you be aware of of the nice discovery my cousin’s girl enjoyed viewing your web page. She came to understand a wide variety of details, not to mention what it is like to possess an ideal giving heart to have many people just gain knowledge of a variety of tortuous topics. You actually exceeded my expectations. Many thanks for imparting such informative, healthy, edifying and in addition fun tips about this topic to Gloria.

  20. Hey there! This is my first visit to your blog! We are a team of volunteers and starting a new project in a community in the same niche. Your blog provided us beneficial information to work on. You have done a outstanding job!

  21. When I originally commented I clicked the “Notify me when new comments are added” checkbox and now each time a comment is added I get four e-mails with the same comment. Is there any way you can remove people from that service? Bless you!

  22. I was wondering if you ever considered changing the layout of your website? Its very well written; I love what youve got to say. But maybe you could a little more in the way of content so people could connect with it better. Youve got an awful lot of text for only having one or two pictures. Maybe you could space it out better?

  23. Write more, thats all I have to say. Literally, it seems as though you relied on the video to make your point. You clearly know what youre talking about, why waste your intelligence on just posting videos to your site when you could be giving us something enlightening to read?

  24. I will immediately seize your rss as I can not to find your e-mail subscription hyperlink or newsletter service. Do you have any? Kindly permit me realize in order that I may just subscribe. Thanks.

  25. hello there and thank you for your information – I have definitely picked up something new from right here. I did however expertise a few technical points using this website, as I experienced to reload the website lots of times previous to I could get it to load properly. I had been wondering if your hosting is OK? Not that I am complaining, but sluggish loading instances times will sometimes affect your placement in google and can damage your high-quality score if advertising and marketing with Adwords. Well I am adding this RSS to my e-mail and could look out for a lot more of your respective intriguing content. Make sure you update this again very soon..

  26. What i don’t realize is actually how you’re not actually much more well-liked than you may be right now. You’re so intelligent. You realize therefore significantly relating to this subject, made me personally consider it from numerous varied angles. Its like women and men aren’t fascinated unless it’s one thing to accomplish with Lady gaga! Your own stuffs excellent. Always maintain it up!

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

目次