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 7507047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:24:26+00:00 2026-05-29T22:24:26+00:00

I am attempting to remove duplicates from a .NET datatable consisting of more than

  • 0

I am attempting to remove duplicates from a .NET datatable consisting of more than 50,000 rows. My approach is simple: I want to sort the datatable alphabetically, then scan through looking for rows that are the same as the row above it.

The problem I’m having is that the datatable “wraps” around when sorted. I use this to sort it:

myDataTable.DefaultView.Sort = "name";

When I view the datatable using the debugger, it is sorted alphabetically in chunks, like so:

Aardvark
Apple
Banana
...(20,000 rows later)...
Aardvark
Angle
Boat

Obviously this ruins my attempt to find duplicates. Is this some sort of optimization behavior of the framework when dealing with large tables? What is going on here?

Solution:

Here is what I was doing..

myDataTable.DefaultView.Sort = "name";
for (int i =0; i< myDataTable.DefaultView.Table.Rows.Count; i++)
{
    var thisRow = myDataTable.DefaultView.Table.Rows[i];
    var prevRow = myDataTable.DefaultView.Table.Rows[i-1];
}

Here is what I should have been doing:

myDataTable.DefaultView.Sort="name";
var myNewDatatable = myDataTable.DefaultView.ToTable();
for (int i =0; i< myNewDatatable.Rows.Count; i++)
{
    var thisRow = myNewDatatable.Rows[i];
    var prevRow = myNewDatatable.Rows[i-1];
}
  • 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-29T22:24:27+00:00Added an answer on May 29, 2026 at 10:24 pm
    myDataTable.DefaultView.Sort = "name";
    

    Here you’re sorting the DataView for the DataTable and not the DataTable.
    So you have to either use the DataView (myDataTable.DefaultView)
    or getting the DataRow‘s of the DataTable sorted by name

    DataRow[] sorted = myDataTable.Select("", "name");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am attempting to remove rows on my asp.net page using the following code:
I am attempting to remove dynamically created controls in C# 2008 asp.net The controls
In attempting to remove all filenames not starting with a particular substring from a
I'm attempting to remove Component elements from the XML below that have File children
I'm attempting to remove certain files from the SD image mounted on the emulator.
I am attempting to remove one more step in my application's release process by
I'm attempting to remove accents from characters in PHP string as the first step
I am attempting to remove a class from an html tag using JavaScript but
I am attempting to remove a CSS class from a particular DIV on-the-fly. I
I am encountering an issue when attempting to remove an object from my Core

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.