回答編集履歴

1

回答を追記

2017/02/10 22:18

投稿

dojikko
dojikko

スコア3939

test CHANGED
@@ -15,3 +15,81 @@
15
15
  ds.Relations.Add("NewTable", AAA.Columns("No"), BBB.Columns("No"))
16
16
 
17
17
  ```
18
+
19
+
20
+
21
+ -追記-
22
+
23
+ ただ結果のDataTableが欲しいだけなら
24
+
25
+ 前提が
26
+
27
+ ```
28
+
29
+ Dim AAA As New DataTable
30
+
31
+ Dim BBB As New DataTable
32
+
33
+ Dim newtable As New DataTable
34
+
35
+
36
+
37
+ AAA.Columns.Add("No")
38
+
39
+ AAA.Columns.Add("Value")
40
+
41
+ AAA.Rows.Add(1, "a")
42
+
43
+ AAA.Rows.Add(2, "b")
44
+
45
+ AAA.Rows.Add(3, "c")
46
+
47
+
48
+
49
+
50
+
51
+ BBB.Columns.Add("No")
52
+
53
+ BBB.Columns.Add("Value")
54
+
55
+ BBB.Rows.Add(1, "A")
56
+
57
+ BBB.Rows.Add(2, "B")
58
+
59
+ BBB.Rows.Add(3, "C")
60
+
61
+
62
+
63
+ newtable.Columns.Add("No")
64
+
65
+ newtable.Columns.Add("Value1")
66
+
67
+ newtable.Columns.Add("Value2")
68
+
69
+ ```
70
+
71
+ みたいなのだと思いますが
72
+
73
+ ```
74
+
75
+ Dim joinresult = AAA.AsEnumerable.Select(Function(x) New With {
76
+
77
+ .No = x.Item("No"),
78
+
79
+ .Value1 = x.Item("Value"),
80
+
81
+ .Value2 = BBB.AsEnumerable.Where(Function(y) y.Item("No") = x.Item("No")).FirstOrDefault?.Item("Value")
82
+
83
+ })
84
+
85
+
86
+
87
+ For Each item In joinresult.ToList
88
+
89
+ newtable.Rows.Add(item.No, item.Value1, item.Value2)
90
+
91
+ Next
92
+
93
+ ```
94
+
95
+ みたいにしてもいいかもしれません