I have a DataTable that contains following columns: type,name,year,version. I want DataTables that contain unique combinations. The table is first divided into multiple tables that have unique name+year combinations. Those tables need to be split again into tables with a unique type. There are a total of 4 types, and 8 different combinations of name + year. So I'm trying to extract a total of 64 Datatables from a single Datatable.
I've tried to first get the distinct combinations of name + year. I've added them to a list(class containing name and Datatable) and if a row from the original table contains that combination i add it to a new DataTable.
DataTable distinctTable = table.DefaultView.ToTable(true, new string[] { name,year });
foreach(var combo in distinctTable)
{
complexlist.add(new ComplexList(row[name].ToString() + row[year].ToString()){table = table.Clone()});
}
foreach (DataRow row in table.Rows)
{
foreach(var item in complexlist)
{
if(item.Name == row[name].ToString() + row[year].ToString())
{
item.table.Rows.Add(row.ItemArray);
}
}
}
now i have 8 different tables and pretty much have to do the same process again to split by type.
Is there any cleaner and less complex way to do this?