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

Top 5 Contributors of the Month
Imran Ghani
Sohaib Khalid

Home >> Code Snippets >> ADO.NET >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Remove Duplicate values from a DataTable

Posted By:Deco       Posted Date: September 15, 2010    Points: 10    Category: ADO.NET    URL: http://www.dotnetspark.com  

The below function will remove the Duplicate values in a DataTable

Below method will remove the duplicate values in a data table


public DataTable GetDistinctRecords(DataTable DTwithDuplicateValues)    
    DataTable DT = new DataTable();        
    DataView dv = DTwithDuplicateValues.DefaultView;     
    //List the column names whose values are to be distinct
    string[] Columns = {'Column1', 'Column2', 'Column3'}   
    DT = dv.ToTable(true, Columns);        
    return DT;    

for e-g, if you want to remove the duplicate values from EmpName, Salary, Designation columns

please list in this line like

string[] Columns = {'EmpName', 'Salary', 'Designation'}  


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

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