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

  • Home
  • SEARCH
  • 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 680339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:21:41+00:00 2026-05-14T01:21:41+00:00

I have a Datatable with Id(guid) and Name(string) columns. I traverse through the data

  • 0

I have a Datatable with Id(guid) and Name(string) columns. I traverse through the data table and run a validation criteria on the Name (say, It should contain only letters and numbers) and then adding the corresponding Id to a List If name passes the validation.

Something like below:-

List<Guid> validIds=new List<Guid>();
foreach(DataRow row in DataTable1.Rows)
{
      if(IsValid(row["Name"])
        {
            validIds.Add((Guid)row["Id"]);
        }

}

In addition to this validation I should also check If the name is not repeating in the whole datatable (even for the case-sensitiveness), If It is repeating, I should not add the corresponding Id in the List.

Things I am thinking/have thought about:-

1) I can have another List, check for the “Name” in the same, If It exists, will add the corresponding Guild
2) I cannot use HashSet as that would treat “Test” and “test” as different strings and not duplicates.
3) Take the DataTable to another one where I have the disctict names (this I havent tried and the code might be incorrect, please correct me whereever possible)

DataTable dataTableWithDistinctName = new DataTable();
dataTableWithDistinctName.CaseSensitive=true
CopiedDataTable=DataTable1.DefaultView.ToTable(true,"Name");

I would loop through the original datatable and check the existence of the “Name” in the CopiedDataTable, If It exists, I wont add the Id to the List.

Are there any better and optimum way to achieve the same? I need to always think of performance. Although there are many related questions in SO, I didnt find a problem similar to this. If you could point me to a question similar to this, It would be helpful.

EDIT :- The number of records might vary from 2000-3000.

Thanks

  • 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-05-14T01:21:42+00:00Added an answer on May 14, 2026 at 1:21 am
        /* I did this entirely in SQL and avoided ADO.NET*/
    
        /*I Pass the CSV of valid object Ids and split that in a table*/
    
    DECLARE @TableTemp TABLE        
    (        
        TempId uniqueidentifier      
    )        
    INSERT INTO @TableTemp 
    SELECT cast(Data AS uniqueidentifier )AS ID FROM dbo.Split1(@ValidObjectIdsAsCSV,',')    
    
    
    /*Self join with table1 for any duplicate rows and update the column value*/    
    UPDATE Table1 
    SET IsValidated=1
    FROM Table1 AS A INNER JOIN @TableTemp AS Temp
    ON A.ID=Temp.TempId 
    WHERE NOT EXISTS (SELECT Name,Count(Name) FROM Table1 
    WHERE A.Name=B.Name
    GROUP BY Name HAVING Count(Name)>1)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a DataTable with a Name column. I want to generate a collection
In JSF is it possible to have a datatable displays records as follows? [Name
I have a strongly typed DataTable created with the VS2005/VS2008 DataSet designer. The table
I have a DataTable that queries out something like below usergroupid...userid......username 1.............1...........John 1.............2...........Lisa 2.............3...........Nathan
I have a DataTable that has a boolean column called [Invalid]. I need to
I have a DataTable which is bound to a GridView. I also have a
I have a datatable that has a date column, but I am stumped as
I have a DataTable. I'd like to sort its default view by a column
In C#/ASP.NET 3.5, I have a DataTable which pulls rows from the database. I
I'm having a bit of a problem. I have a datatable in the parent

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.