主キー(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行書き込みに変数「氏名」が出力されれば成功です。
無事に出力されました。
66件のフィードバック
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
I have learn some excellent stuff here. Certainly value bookmarking for revisiting.
I surprise how so much attempt you place to make any such
wonderful informative website.
Here is my web site vpn coupon code 2024
I know this if off topic but I’m looking into starting
my own weblog and was curious what all is required facebook vs eharmony to find love online get setup?
I’m assuming having a blog like yours would cost a
pretty penny? I’m not very internet savvy so
I’m not 100% certain. Any tips or advice would be greatly appreciated.
Cheers
Hi there! Quick question that’s entirely off topic. Do
you know how to make your site mobile friendly? My website looks weird when browsing from my iphone
4. I’m trying to find a template or plugin that might
be able to resolve this problem. If you have any suggestions, please share.
Appreciate it!
Here is my web blog; eharmony special coupon code 2024
You have made some good points there. I looked on the internet to find out more about the issue
and found most people will go along with your views
on this site.
Feel free to visit my site :: nordvpn special coupon code 2024
mexican rx online: mexican pharmacy online – medicine in mexico pharmacies
medicine in mexico pharmacies: mexican pharmacy online – pharmacies in mexico that ship to usa
canadian drugs pharmacy: best canadian pharmacy online – canadian drugs pharmacy
medication from mexico pharmacy: medication from mexico pharmacy – mexico pharmacy
top online pharmacy india: top 10 online pharmacy in india – indian pharmacies safe
best canadian pharmacy: safe canadian pharmacies – canadian pharmacy near me
buying from online mexican pharmacy: reputable mexican pharmacies online – buying from online mexican pharmacy
canadian neighbor pharmacy: canadapharmacyonline – canadian drugs online
india pharmacy mail order: pharmacy website india – indian pharmacy paypal
pharmacy website india: cheapest online pharmacy india – online pharmacy india
legit canadian pharmacy: canadian pharmacy 365 – canada pharmacy reviews
п»їbest mexican online pharmacies: mexican drugstore online – п»їbest mexican online pharmacies
http://ciprodelivery.pro/# cipro
http://paxloviddelivery.pro/# paxlovid pill
purchase amoxicillin 500 mg [url=http://amoxildelivery.pro/#]amoxicillin without a prescription[/url] can i buy amoxicillin over the counter in australia
https://doxycyclinedelivery.pro/# doxycycline 100mg tablet
https://ciprodelivery.pro/# ciprofloxacin 500 mg tablet price
cost cheap clomid price [url=https://clomiddelivery.pro/#]how to buy cheap clomid price[/url] where to get clomid pills
http://paxloviddelivery.pro/# paxlovid generic
https://doxycyclinedelivery.pro/# doxycycline order online
https://paxloviddelivery.pro/# п»їpaxlovid
cost generic clomid for sale [url=http://clomiddelivery.pro/#]can i order generic clomid pills[/url] order generic clomid tablets
https://clomiddelivery.pro/# can i get clomid price
http://amoxildelivery.pro/# amoxicillin 500 mg capsule
cipro 500mg best prices [url=https://ciprodelivery.pro/#]buy cipro online without prescription[/url] buy cipro online without prescription
https://doxycyclinedelivery.pro/# doxycycline usa
https://ciprodelivery.pro/# cipro online no prescription in the usa
antibiotics cipro [url=https://ciprodelivery.pro/#]buy generic ciprofloxacin[/url] cipro ciprofloxacin
https://paxloviddelivery.pro/# paxlovid cost without insurance
http://clomiddelivery.pro/# can i get clomid
paxlovid cost without insurance [url=http://paxloviddelivery.pro/#]п»їpaxlovid[/url] paxlovid covid
http://paxloviddelivery.pro/# paxlovid buy
https://clomiddelivery.pro/# cheap clomid without insurance
doxycycline online pharmacy [url=https://doxycyclinedelivery.pro/#]doxycycline hyclate 100mg price[/url] doxycycline 40 mg generic coupon
http://doxycyclinedelivery.pro/# buy doxycycline mexico
buy prescription drugs from india: top 10 online pharmacy in india – top 10 online pharmacy in india
viagra professional online pharmacy: best online accutane pharmacy – doxycycline generics pharmacy
reputable indian online pharmacy: top 10 pharmacies in india – world pharmacy india
ketoconazole pharmacy: online pharmacy no prescription synthroid – integrity rx specialty pharmacy
amlodipine besylate online pharmacy: cialis american pharmacy – Levitra with Dapoxetine
people pharmacy store: your pharmacy online – mexican pharmacy fluconazole
Online medicine order: mail order pharmacy india – india online pharmacy
medicine in mexico pharmacies: pharmacies in mexico that ship to usa – mexican border pharmacies shipping to usa
top 10 pharmacies in india: top 10 pharmacies in india – india pharmacy
farmacia online barata: cialis 20 mg precio farmacia – farmacias online baratas
farmacia online barata y fiable: farmacias online seguras – farmacia online madrid
farmacia online 24 horas: precio cialis en farmacia con receta – farmacia online envГo gratis
farmacie online affidabili: Cialis generico 5 mg prezzo – Farmacia online piГ№ conveniente
farmacia online senza ricetta: farmacia online migliore – farmacia online
miglior sito per comprare viagra online: viagra online siti sicuri – viagra generico recensioni
farmacie online affidabili: BRUFEN 600 mg 30 compresse prezzo – Farmacia online miglior prezzo
viagra 100 mg prezzo in farmacia: viagra online siti sicuri – pillole per erezione in farmacia senza ricetta
farmacie online affidabili: Cialis generico controindicazioni – farmaci senza ricetta elenco
lasix for sale: furosemide online – furosemide
cheap Rybelsus 14 mg: buy rybelsus – rybelsus generic
buy prednisone no prescription: prednisone over the counter cost – buy prednisone from india
lasix tablet: lasix for sale – generic lasix
mexico pharmacies prescription drugs: mexican pharmacy – reputable mexican pharmacies online
mexican mail order pharmacies http://mexicanpharma.icu/# mexican online pharmacies prescription drugs
buying prescription drugs in mexico online
mexican drugstore online: mexican pharma – medicine in mexico pharmacies
mexico drug stores pharmacies
rybelsus pill: rybelsus pill – buy rybelsus online
buy ozempic: ozempic cost – buy ozempic
ozempic cost: ozempic cost – ozempic cost
ozempic online: buy cheap ozempic – ozempic online
semaglutide cost: semaglutide tablets – semaglutide online
buy rybelsus online: rybelsus coupon – rybelsus pill
https://stromectol.agency/# minocycline price
https://zithromax.company/# zithromax over the counter