Solved

Remove duplicate rows from dataTable

Posted on 2010-09-19
10
741 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
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
 
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

706 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now