Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8019397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:22:43+00:00 2026-06-04T21:22:43+00:00

I am new to programming so this may seem somewhat straightforward, but I cannot

  • 0

I am new to programming so this may seem somewhat straightforward, but I cannot seem to figure it out.

I am trying to find duplicate values that are in a datatable in one column of the values.

Here is what I was trying to do it with.

DataRow[] dupresults = dt.Select("PROV_NEW");
TableIssues = string.Empty;
DataTable dtTemp = dt.DefaultView.ToTable(true, "NEW_PROV");

if (dupresults.Length == 0)
{
    return true;
}
else
{
    foreach (DataRow item in dupresults)
    {
        Console.WriteLine(item[1]);
        TableIssues += "Provider Code is not unique for " + item[1].ToString() + ". Revise non-unique codes.\r\n\n\n\n";
    }
    return false;
}

Alright, but I am also having it search to make sure that there are no empty fields in PROV_NEW too. so I would not know where to put that. I am very new to c#. I just started last week. I am doing side projects for my father’s company.

private bool ValidateTable(DataSets.Setup.SETUP_MWPROVDataTable dt, out string TableIssues)
    {
        try
        {
            //NewCode not used for other row
            DataRow[] result = dt.Select("PROV_NEW = ''");
            DataRow[] dupresults = dt.Select("PROV_NEW");
            TableIssues = string.Empty;
            DataTable dtTemp = dt.DefaultView.ToTable(true, "NEW_PROV");



            if (dupresults.Length == 0)
            {

                return true;
            }
            else
            {
                var duplicates = dt.AsEnumerable()
               .Select(dr => dr.Field<string>("PROV_NEW"))
               .GroupBy(x => x)
               .Where(g => g.Count() > 1)
               .Select(g => g.Key)
               .ToList();

                foreach (DataRow item in dupresults)
                {
                    Console.WriteLine(item[1]);
                    TableIssues += "Provider Code is not unique for " + item[1].ToString() + ". Revise non-unique codes.\r\n\n\n\n";
                }
                return false;
            }


            if (result.Length == 0)
            {
                //TODO: Add Next Step for validation

                return true;

            }
            else
            {
                foreach (DataRow item in result)
                {
                    Console.WriteLine(item[1]);
                    TableIssues += "Provider code " + item[1].ToString() + " is blank. Add new Provider code for " + item[1].ToString() +".\r\n\n\n";
                }


                return false;
            }

           }
        catch (Exception)
        {

            throw;
        }
    }


}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T21:22:44+00:00Added an answer on June 4, 2026 at 9:22 pm

    LINQ can help you here:

    var duplicates = dt.AsEnumerable()
                       .Select(dr => dr.Field<string>("PROV_NEW"))
                       .GroupBy(x => x)
                       .Where(g => g.Count() > 1)
                       .Select(g => g.Key)
                       .ToList();
    
    // Now work with the set of duplicates
    

    Alternatively:

    HashSet<string> providers = new HashSet<string>();
    foreach (var provider in dt.AsEnumerable()
                               .Select(dr => dr.Field<string>("PROV_NEW")))
    {
        if (!providers.Add(provider))
        {
            // This provider is a duplicate
        }
    }
    

    (This works because HashSet<T>.Add returns false if the value already exists in the set.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question may seem daft (I'm a new to 'programming' and should probably stop
I'm fairly new to Android programming, so this may be a simple question, but
I've been attempting to figure this out for forever now (I'm new to programming)
I am new in programming and this question may really be stupid but I
This may be chalked up to exhaustion, but I am new to MVC programming
i am new in programming under linux and trying to get working this code:
i am new kernel programming.i have been trying to load this driver program for
This is a kind of a newb question but I'm really new to programming
I think this is a very simple question, but I’m new to programming so
I'm new to C++, only been programming a few days so this might seem

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.