我有以下数据表
表1:
+-----------+------+------+
| catalogid | name | snum |
+-----------+------+------+
| 353 | xx | 4 |
| 364 | yy | 3 |
| 882 | zz | 3 |
| 224 | mm | 71 |
| 999 | kk | 321 |
| 74 | kk | 4 |
| 54 | ii | 5 |
| 11 | u | 6 |
| 23 | yy | 6 |
+-----------+------+------+
表2:
+-----------+----------+--------------+
| catalogid | numitems | ignoreditems |
+-----------+----------+--------------+
| 353 | 4 | 0 |
| 364 | 10 | 0 |
| 882 | 2 | 0 |
| 224 | 0 | 7 |
+-----------+----------+--------------+
使用 LINQ 我想加入它们并将结果复制到新的数据表中。他们都共享catalogid
,结果应该只显示他们的catalogid存在于table2中的记录
结果:
+-----------+------+------+-----------+---------------+
| catalogid | name | snum | numitems | ignoreditems |
+-----------+------+------+-----------+---------------+
| 353 | xx | 4 | 4 | 0 |
| 364 | yy | 3 | 10 | 0 |
| 882 | zz | 3 | 2 | 0 |
| 224 | mm | 71 | 0 | 7 |
+-----------+------+------+-----------+---------------+
这是我的尝试,但它不起作用:
Dim query = From a In oresult.AsEnumerable
Group Join b In products.AsEnumerable
On a.Field(Of Integer)("catalogid") Equals b.Field(Of Integer)("catalogid")
Into Group
query.copytodatatable
CopyToDatatable
不工作,我不知道为什么