Select Distinct on Column from DataSet / DataTable

By Peter Bromberg

This is an easy way to provide a method that will return a DataTable of distinct rows based on a named column.


public DataTable GetDistinctTableFromDataset(DataSet ds, string columnName)
        {      
           DataView dv = ds.Tables[0].DefaultView;
           DataTable newTable = dv.ToTable(true, columnName);
             return newTable;
        }

Select Distinct on Column from DataSet / DataTable  (1231 Views)