Efficiently Remove Duplicates in Dataset

Remember, the pain of removing duplicates in fetched dataset by looping, comparing etc.

it can be handled easily by using DataView.ToTable Method. The syntax is below.

DataView.ToTable(bool distinct, string[] columnNames)

distinct: If it's true, the returned DataTable contains rows that have distinct values for all its columns specified in the second parameter. Default value is false.

columnNames: A string array that contains a list of the column names to be included in the returned table. The order of columns in returned table would be same as it’s appear in the array.

Ex1

DataTable temp = dt.DefaultView.ToTable(true, "Region");

Ex2

DataTable temp = dt.DefaultView.ToTable(true, "Region", "City");

Reference:

DataView.ToTable Method

X

Build smarter apps with Machine Learning, Bots, Cognitive Services - Start free.

Start Learning Now