如何找到在一列中重复一个DataTable,并用星asp.net VB使他们 [英] How to find duplicates in a column in a datatable and make them with a star asp.net vb

查看:252
本文介绍了如何找到在一列中重复一个DataTable,并用星asp.net VB使他们的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个内存数据表,我需要标记重复.....例如..

I have a in-memory DataTable and I need to mark the duplicates ..... for example ..




From To

我可能会做这样的事情。

I would probably do something like ..

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

对不起,问这么多问题...我的头被烧毁..没有出来..而该项目需要很快完成。

Sorry for asking so many questions ... My head is burnt .. nothing came out .. and this project is needing to finish very soon ..

推荐答案

您可以使用 LINQ到数据表

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;

这篇关于如何找到在一列中重复一个DataTable,并用星asp.net VB使他们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆