You cannot do a group by inside a
DataTable
. You need to do the group by in the query that gets you the data. If you can't do this, you need to convert your data out, perform the group by and then allocate it back to a DataTable. Here's an example of how to do this:
public DataTable GroupByName(DataTable table)
{
return table.AsEnumerable().GroupBy(gb => gb.Field<string>("Name")).Select(sel => sel.First()).CopyToDataTable();
}