全て
| カテゴリ未分類
| 通常
| 数学
| 投資
| 副業
| 転職・就職
| ブログ
| 株Stock
| VBA
| SharePoint
| REST API
| RenderListDataAsStream
| PowerAutomateDesktop
| Graph API
| PowerApps
| PowerAutomate
| PowerFx
| OfficeScriptオフィススクリプト
| PowerAutomate日時Excel日時相互関係
| PowerShell
| Dataverse
| UiPath
| OneDrive
| LINQ
| VB.NET
| C#.NET
| WPFC#.NET
| Git
カテゴリ:LINQ
Imports System Imports System.Data Imports System.Linq Module Program Sub Main(args As String()) ' サンプルのDataTable1を作成します Dim table1 As New DataTable() table1.Columns.Add("ID", GetType(Integer)) table1.Columns.Add("Name", GetType(String)) table1.Rows.Add(1, "John") table1.Rows.Add(2, "Alice") table1.Rows.Add(3, "Bob") ' サンプルのDataTable2を作成します Dim table2 As New DataTable() table2.Columns.Add("ID", GetType(Integer)) table2.Columns.Add("Age", GetType(Integer)) table2.Rows.Add(1, 30) table2.Rows.Add(3, 25) table2.Rows.Add(4, 35) ' 外部結合を行います Dim query = From row1 As DataRow In table1.AsEnumerable() Group Join row2 As DataRow In table2.AsEnumerable() On row1.Field(Of Integer)("ID") Equals row2.Field(Of Integer)("ID") Into JoinedTable = Group From row3 In JoinedTable.DefaultIfEmpty() Select New With { .ID = row1.Field(Of Integer)("ID"), .Name = row1.Field(Of String)("Name"), .Age = If(row3 IsNot Nothing, row3.Field(Of Integer)("Age"), Nothing) } ' 結果を出力します For Each item In query Console.WriteLine($"ID: {item.ID}, Name: {item.Name}, Age: {If(item.Age IsNot Nothing, item.Age.ToString(), "N/A")}") Next End Sub End Module お気に入りの記事を「いいね!」で応援しよう
Last updated
2024.02.25 07:26:21
[LINQ] カテゴリの最新記事
|