SoFunction
Updated on 2025-03-10

2 ways to remove duplicate rows in DataTable

The first type is to use Linq to query expressions, the code is as follows

DataTable testtable = new DataTable();
      ("ID");
      ("ProductName");

      ("1", "1");
      ("1", "1");
      ("1", "1");
      ("2", "2");
      ("3", "3");
      DataTable finalltable = new DataTable();
      finalltable = ();
      ();
      
      var rows = from row in () group row by row["ID"] into myrow select ();
      foreach (DataRow row in rows)
      {
        (row);
      }

The second method

Use dataview to filter datatable

testtable = (true, new string[] { "ID", "ProductName" });