1

我有一个内存DataTable,我需要标记重复项.....例如..

在此处输入图像描述在此处输入图像描述

我可能会做类似..

    For each dtrow in dt.rows
    If dtrow("Country") Is one of Duplicates then
            dtrow("Country") += "*"
    end if
    Next

抱歉问了这么多问题......我的头被烧毁了..什么都没出来..这个项目需要很快完成..

4

1 回答 1

5

你可以使用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;
于 2012-05-15T12:30:01.680 回答