I have a datatable containing a Bool(bit) Column.
a b
------ ------
1 10
0 20
1 30
0 20
1 10
I wish to split this into 2 independently sortable datatables based on this value (column a)
I've had a look and found an old question:
Split a DataTable into 2 or more DataTables based on Column value
Which gave this:
List<DataTable> result = myDataTable.AsEnumerable()
.GroupBy(row => row.Field<Boolean>("a"))
.Select(g => g.CopyToDataTable())
.ToList();
But the result isn't a list of datatables I can refer to using result[0]
and result[1]
Like I'd expected.
When I hit result[1]
I get:
"Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index"
I'd add a comment to ask but the thread is well over 2 years old and I'm afraid I'd not get a response.
Can anyone advise of a way to achieve what I'm needing either using this code or something fresh?