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);
public static DataTable GetDistinctRecords(DataTable dt, string[] Columns)
{
DataTable dtUniqRecords = new DataTable();
dtUniqRecords = dt.DefaultView.ToTable(true, Columns);
return dtUniqRecords;
}
Thanks,
Imdadhusen