How to check for duplicate entries in Data Table - VB.Net

Posted on 2011-05-03
Last Modified: 2012-05-11
Hello Experts,

I have data table comprised of 3 coulmns (Channel Name, Channel ID, Channel Type)

I'm looking for an efficient code for looping through the table to detect if I have duplicated channel names.

Someting along the following lines:

For Each drRow in dtChannelsList.Rows
 code goes here to check if drRow.item("ChannelName") is duplicate

Appreciate your help

Question by:Mehawitchi
    LVL 16

    Accepted Solution


    Please try following code

    For Each drRow In dtChannelsList.Rows
                Dim drs As DataRow() = dtChannelsList.Select("ChannelName='" + drRow("ChannelName") + "'")
                If drs.Length > 0 Then
                    'Add Your code here to handle the duplication
                End If

    Open in new window


    Author Comment

    Hello IJZ,

    Thank you for the quick response.

    I think I should use 1 instead of 0 in the following:
    If drs.Length > 0
    because there will be already one record for the same name. Right?

    LVL 16

    Expert Comment

    by:Imran Javed Zia
    Yes you are right

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    In my previous two articles we discussed Binary Serialization ( and XML Serialization ( In this article we will try to know more about SOAP (Simple Object Acces…
    Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
    This video discusses moving either the default database or any database to a new volume.
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now