Learn how to a build a cloud-first strategyRegister Now


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

Posted on 2011-05-03
Medium Priority
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 VB.net 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
  • 2
LVL 16

Accepted Solution

Imran Javed Zia earned 2000 total points
ID: 35513151

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

ID: 35513185
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
ID: 35513262
Yes you are right

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

810 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