我正在尝试从数据表中的特定列中检索所有不同的值。数据表中的列名称是“Count”。我有 2240 行,“计数”列中有 6 个不同的值。问题是,当我执行以下代码时,它给出的是行数而不是 6 个不同的值。
Dim counts = (From row In loadedData
Select row.Item("Count")).Distinct()
For Each i In counts
MsgBox(i)
Next
我如何修改它以检索 6 个不同的值,而不是给出总行数?
您只需选择列并使用Enumerable.Distinct
:
Dim distinctCounts As IEnumerable(Of Int32) = loadedData.AsEnumerable().
Select(Function(row) row.Field(Of Int32)("Count")).
Distinct()
在查询语法中(我什至不知道Distinct
VB.NET 直接支持):
distinctCounts = From row In loadedData
Select row.Field(Of Int32)("Count")
Distinct
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)