次の方法で共有


Efficiently remove duplicates in dataset

Hi folks,

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: https://msdn.microsoft.com/en-us/library/wec2b2e6.aspx

Comments

  • Anonymous
    October 28, 2012
    Thanks for this useful tip ( useful at least for me as i was ignoring this possible use of a DataView )