我有一个内存DataTable
,我需要标记重复项.....例如..
从
到
我可能会做类似..
For each dtrow in dt.rows
If dtrow("Country") Is one of Duplicates then
dtrow("Country") += "*"
end if
Next
抱歉问了这么多问题......我的头被烧毁了..什么都没出来..这个项目需要很快完成..
你可以使用LINQ-to-DataTable
:
Dim dups = From row In dt.AsEnumerable()
Let country = row.Field(Of String)("Country")
Group row By country Into DupCountries = Group
Where DupCountries.Count() > 1
Select DupCountries
For Each dupCountryRows In dups
For Each row In dupCountryRows
row("Country") = row.Field(Of String)("Country") & "*"
Next
Next
或者使用 C# 语法:
var dups = from row in dt.AsEnumerable()
let id = row.Field<string>("Country")
group row by country
into DupCountries where DupCountries.Count() > 1
select DupCountries;