2
DataView view = new DataView(dt);
dt= view.ToTable(true, "id");

If i have 2 columns "id" and "name" i need to get the distinct "id" but not the distinct "name" but i need to keep the column "name" in my datatable what shall i do?

Himanshu Suthar
  • 161
  • 1
  • 5
  • 19

1 Answers1

3
DataView view = new DataView(table);
DataTable distinctValues = view.ToTable(true, "Column1", "Column2" ...);

If i have 2 columns "id" and "name" i need to get the distinct "id" but not the distinct "name" but i need to keep the column "name" in my datatable what shall i do?

OK, then i need grouping, not distinct.I could do it with Linq to DataSet: table.AsEnumerable().GroupBy(row => row.Field<int>("id")).Select(group =>group.First()).CopyToDataTable()

Zaheer Ul Hassan
  • 771
  • 9
  • 24