Error
  • JHTMLicon not supported. File not found.
  • JHTMLicon not supported. File not found.
  • JHTMLicon not supported. File not found.

dtuniqrecords

Select Unique records based on specified fields or column from DataTable
Monday, 19 December 2011 02:18
This will help you only when you have to filter distinct records based on specified fields.
e.g. I have a table called UserDetail which contains the following fields:

UserID | Name | Mobile | Email | City | State

Now I want to only display distinct records with Name, City and State, then you can use:

string[] TobeDistinct = {"Name","City","State"};
DataTable dtDistinct = GetDistinctRecords(DTwithDuplicate, TobeDistinct);

//Following function will return Distinct records for Name, City and State column.
public static DataTable GetDistinctRecords(DataTable dt, string[] Columns)
{
DataTable dtUniqRecords = new DataTable();
dtUniqRecords = dt.DefaultView.ToTable(true, Columns);
return dtUniqRecords;
}

Read more: http://feeds.dzone.com/~r/dzone/snippets/~3/b62ajuXbh28/14235

 


Taxonomy by Zaragoza Online