>>>Hi again,
>>>
>>>I have a dataset that I need to break into several (one at a time) based on the following logic. I will refer to this, initial, data set as BigDataSet.
>>>
>>>The dataset has a column (defined as a variable, e.g. ColumnGroup='MYCOL1'). I need to group the BigDataSet on the column ColumnGroup. Then get all rows for first group into a SmallDataSet (rows of the same MYCOL1). Then go to the next group and create another SmallDataSet. Once I create a SmallDataSet I will write it to an XML file. Therefore, I don't need all SmallDataSets, just one at a time.
>>>
>>>TIA for any suggestions.
>>
>>Assuming the BigDataSet we are talking about is actually just a single DataTable, you should be able to use the LINQ GroupBy method (
https://msdn.microsoft.com/en-us/library/bb534501%28v=vs.100%29.aspx) to group by the data in that column followed by the CopyToDataTable method (
https://msdn.microsoft.com/en-us/library/bb396189%28v=vs.110%29.aspx) to put them back into separate DataTables if need be.
>
>Thank you, Rob. I don't know anything about LINQ so I will follow the link you posted and see if I can figure it out.
Assuming BigDataSet is a Dataset and not a table (and that the table is 'MyTable') then something like:
var keys = BigDataSet.Tables["MyTable"].AsEnumerable().GroupBy(r => r.Field<string>("MYCOL1"));
foreach (var group in keys)
{
IEnumerable<DataRow> itemsForKey = group.Select(x=>x);
}