Click here to Skip to main content
16,001,976 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Experts,

Here is something tricky. I have Dataset1 as below
Tireline	Class	Item
glass1	        2	
glass1       	10	
Eagle1	        2	
Eagle1	        10	



And I want them in two different datatables as below

class	Tireline	Item
2	glass1	
2	Eagle1	


And

class	Tireline	Item
10	glass1	
10	Eagle1	




Please help me with this
Posted
Updated 14-May-15 9:05am
v3
Comments
Sascha Lefèvre 14-May-15 15:05pm    
Your question is not quite clear to me. Do you speak of a System.Data.DataSet? Those only contain System.Data.DataTables but you showed the "content" of the DataSet in form of a single table.

1 solution

This is easy to do with LINQ:
C#
DataTable sourceTable = dataSet.Tables[0];

foreach (var group in sourceTable.AsEnumerable().GroupBy(row => row.Field<int>("Class")))
{
    var newTable = group.CopyToDataTable();
    newTable.TableName = "Class" + group.Key;
    dataSet.Tables.Add(newTable);
}
 
Share this answer
 
v2
Comments
Maciej Los 16-May-15 7:16am    
5ed!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900