Solved

Remove duplicate rows from dataTable

Posted on 2010-09-19
10
745 Views
Last Modified: 2013-12-20
Working in ado.net

I have a DataTable called dt
For the sake of simplicity, it has two columns- column called Name and one called x
I would like to remove a row if the value the Name column in one row is the same as a value in the Name column in another row. The x values may be different but that doesnt matter

Please help.....

0
Comment
Question by:sebastiz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 5

Accepted Solution

by:
roxviper earned 500 total points
ID: 33711751
0
 
LVL 3

Expert Comment

by:AccessYourBiz_Com
ID: 33711783
create a new table called DeleteNames or call it whatever you want. It should have just one field, "Name", same as your Name table. Make it the primary key and save.
Using the duplicate query wizard, create a query of duplicates from the Name table.
Change this query top an Append Query and append the records to the new table "DeleteNames"
Then create another query and include the the DeleteNames table and the other table that you want to delete the records from. Create a join between the two Name columns.
Change this to a Delete Query. Place the askerick from the table you want to delete from in the query grid.
Run the query it will delete the records. If you have a probke with updatable recordset then you muct go an add an index to the Name field of the table you are deleting from.
0
 
LVL 3

Expert Comment

by:AccessYourBiz_Com
ID: 33712416
I re-read my post and made some typos corrections. See below:

Create a new table called DeleteNames or call it whatever you want. It should have just one field, "Name", same as your Name table. Make it the primary key and save.
Using the duplicate query wizard, create a query of duplicates from the Name table.
Change this query to an Append Query and append the records to the new table "DeleteNames".
Then create another query and include the "DeleteNames" table and the other table that you want to delete the records from. Create a join between the two Name columns of each table.
Change this duplicates query to a Delete Query. Place the asterick from the table you want to delete the records from onto the query grid. Nother else should be in the query grid.
Run the delete query and it will delete the duplicate records. If you get an error that it is not an updatable recordset then you must add an index to the Name field of the table you are deleting from.
0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
LVL 19

Expert Comment

by:Shahan Ayyub
ID: 33717060

Hi!

Try this:
  • Create new Datatable dtUnique.
  • Select distibct records via 'distinct' query. like select distinct [name] from [tablename]
  • Copy records in dtUnique.
  • delete 'dt'
0
 
LVL 19

Expert Comment

by:Shahan Ayyub
ID: 33717067
sorry distinct not distibct.
0
 

Author Comment

by:sebastiz
ID: 33717219
Hi Shahan

But will a distinct query look at the whole row, or can I select DISTINCT on the basis of an item in a named column being the same in two rows?

 
0
 
LVL 13

Expert Comment

by:Naman Goel
ID: 33718189
distinct will give distinct rows on the basis of specified column values

http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataset/thread/ed9c6a6a-a93e-4bf5-a892-d8471b84aa3b
0
 
LVL 19

Expert Comment

by:Shahan Ayyub
ID: 33726834
Hi!

Distinct will give you the records on the basis of columns.

This can give an idea what i want to do:

        SELECT Distinct a.*
        FROM [Practice].[dbo].[products] a

This will select all unique records.
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 34049807
This question has been classified as abandoned and is being closed as part of the Cleanup Program.  See my comment at the end of the question for more details.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

730 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