473,403 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Keep duplicate rows using hashtable

Hi,

Here is the code to eliminate duplicate rows, but what if I want to keep
them and elimiante all other the unique ?
public void RemoveDuplicateRows(DataTable dTable,string colName)
{
Hashtable hTable = new Hashtable();
ArrayList duplicateList = new ArrayList();

foreach(DataRow drow in dTable.Rows)
{
try
{
hTable.Add(drow[colName],string.Empty);
}
catch
{
duplicateList.Add(drow);
}
}

foreach(DataRow dRow in duplicateList)
dTable.Rows.Remove(dRow);
}

Thanks
Jul 26 '06 #1
1 4778
Hung,

You will have to make two passes. On the first pass, you will have to
add the rows to the list that is stored with a certain key.

Then, you have to cycle through all the lists. If there is only one
item in the list that is related by a certain key, then you delete it.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"hung tran" <om*****@gmx.netwrote in message
news:i3********************************@4ax.com...
Hi,

Here is the code to eliminate duplicate rows, but what if I want to keep
them and elimiante all other the unique ?
public void RemoveDuplicateRows(DataTable dTable,string colName)
{
Hashtable hTable = new Hashtable();
ArrayList duplicateList = new ArrayList();

foreach(DataRow drow in dTable.Rows)
{
try
{
hTable.Add(drow[colName],string.Empty);
}
catch
{
duplicateList.Add(drow);
}
}

foreach(DataRow dRow in duplicateList)
dTable.Rows.Remove(dRow);
}

Thanks

Jul 26 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Russell | last post by:
I'm using MySQL 4.1.1 I've inherited a database which has some (almost) duplicate rows. The databse is like this. userID userPosition userDepartment
3
by: shine | last post by:
I am trying to add an integer array to a hashtable. While adding to hashtable I want to check the duplicates in array, the way I want to do is add the key(the integer stored in array) if a...
3
by: dan graziano | last post by:
Hi, How do you suggest is the best way to check for duplicate rows in an access table. And once one knows if there are duplicates, to remove all but one. In my access table, there are 5...
1
by: TaeHo Yoo | last post by:
I have a table that has more than 1 milion rows so practically it is impossible to remove all duplicate rows by hand. Could you help me to remove those duplicate rows at all? This table doesn't...
1
by: Asha | last post by:
greetings, does anyone have any idea how to delete duplicate rows in a dataset gracefully (the fast and easy way)
7
by: Jon Maz | last post by:
Hi, I have a MySql problem I hope someone can help me with. I'm trying to run an update on a linking table, the update is running into a Primary Key constraint violation, and in my workaround...
2
by: thithu | last post by:
In Sql Server table , there are some duplicate rows i want to delete the duplicate rows without using Cursors and Temp Table
5
jamesd0142
by: jamesd0142 | last post by:
My manager and I where looking at some complex code to eliminate duplicate records in a database table. then it hit me how its done easily... so i thought i'd share it... In English:...
4
by: ravir81 | last post by:
Hi, I am currently working on excel validation using Perl. I am new to Excel validation but not for Perl. I have a question regarding one of the validation. Could anyone please tell me how to get...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.