.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> VB.Net >> Post New QuestionBookmark and Share Subscribe to Forum

how to remove duplicate records from a datatable

Posted By: Santosh     Posted Date: September 15, 2010    Points:2   Category :VB.Net
Hi

can any body plz tell me how to remove duplicate record from datatable.

Ex:
Below is my Datatable.

ID Name Empid Adress DOB Department
1 Santosh c100 KL 11.04.1984 Developer
2 Ramesh c101 B'lore 12.05.1984 Developer
3 Santosh c103 KL 11.04.1984 Developer
4 Subash c104 B'lore 25.12.1985 Developer

i want to remove duplicate Records according to the (Name,Address and DOB) Column.

means if for both the records Name,Address and DOB is same then i want to remove one (no need to check other details like id,Empid and Department)
in the above datatable for ID =1 and 3 having duplicate records according to the (Name,Address and DOB) column.


so my output Datatable should be
ID Name Empid Adress DOB Department
1 Santosh c100 KL 11.04.1984 Developer
2 Ramesh c101 B'lore 12.05.1984 Developer
4 Subash c104 B'lore 25.12.1985 Developer

i am working on vb.net

Thanx in advance.......

Santosh


Responses
Author: Deco             
Posted Date: September 15, 2010     Points: 5   

Please refer this link

http://www.dotnetspark.com/kb/2639-remove-duplicate-values-from-datatable.aspx

Regards,
Deco
Author: Santosh             
Posted Date: September 15, 2010     Points: 5   

hi Alwyn

ur code will return the correct result but only that 3 columns

but i want same this result with all the columns

means datatable should be contain all the columns not only above 3....


Regards
Santosh

Author: Rajshree             
Posted Date: September 15, 2010     Points: 5   

How To Check and Remove Duplcate Data in Sql Server


Here is a simple query to check for the duplicacy of data

Suppose there is a table names Student

There is a column 'ID'

Query:


Select id,Count(*) from Student groupby id having count(*) >1

Result:

The Above query will display the records of all the students having same id

Save the Distinct Result in another table having Same structure n remove all duplicate records from the parent table i.e Student

Now sup duplicate table is temp_Student
Now add the result in the student table

using Query

Insert into Student select * from temp_student






Author: Syed Shakeer Hussain             
Posted Date: September 15, 2010     Points: 5   

Hi,

Below query is usefull to delete duplicate records:-

with CTE as(select row_number() over(partition by name,Address ,DOB order by name) row,name,Empid Address ,DOB from tableName) 
Delete from CTE where row >1


To see the result
select * from tablename

Author: Deco             
Posted Date: September 16, 2010     Points: 5   

Santosh,

I just gave you a sample,

you can add all the columns you want.

Regards,
Deco
Author: Santosh             
Posted Date: September 17, 2010     Points: 5   

hi Rajshree

my requirement is not like what u gave ...

actually i m doing every thing in frond end not in query or SP.

first i m binding the datagrid from the database...

after that i m adding removing from the grid...

finally i m saving this grid records to the datatbase..

before saving i m inserting this through Datatable

so before saving the records i want to check wheather any record is duplicate or not based on (Name,Address and DOB)

if duplicate then i want to remove and save into database...


Regards
Santosh



Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend