sebastiz
asked on
Remove duplicate rows from dataTable
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.....
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.....
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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.
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'
sorry distinct not distibct.
ASKER
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?
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?
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
http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataset/thread/ed9c6a6a-a93e-4bf5-a892-d8471b84aa3b
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.
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
This will select all unique records.
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.
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.