Well... Your code looks good. I tested above query and it works as expected. See:
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("ID", typeof(int)));
dt.Columns.Add(new DataColumn("Note", typeof(string)));
dt.Rows.Add(new object[]{1, "A"});
dt.Rows.Add(new object[]{1, "B"});
dt.Rows.Add(new object[]{1, "C"});
dt.Rows.Add(new object[]{2, "D"});
dt.Rows.Add(new object[]{2, "E"});
dt.Rows.Add(new object[]{2, "F"});
dt.Rows.Add(new object[]{3, "G"});
dt.Rows.Add(new object[]{3, "H"});
dt.Rows.Add(new object[]{3, "I"});
dt.Rows.Add(new object[]{4, "J"});
dt.Rows.Add(new object[]{4, "K"});
dt.Rows.Add(new object[]{4, "L"});
List<datatable> result = dt.AsEnumerable()
.GroupBy(x=>x.Field<int>("ID"))
.Select(grp=>grp.CopyToDataTable())
.ToList();
"
Invalid agument
" error is easy to resolve. So, you have to debug your programme to find out where the error occur.
In the meanwhile, please read this:
Invalid procedure call or argument (Error 5)[
^]
[EDIT]
Raja Ganapathy wrote:
[in the comment to the solution1]
i go through your code sir.i have n numbers of columns i want to split first 24 columns and rows from the data table.How to do it.
If you want to get only few columns, replace:
.Select(grp=>grp.CopyToDataTable())
with
.Select(grp=>grp.Select(a=>new{
Col1 = a.Field<Type>("Name1"),
Col2 = a.Field<Type>("Name2"),
...
ColN = a.Field<Type>("NameN")
}).CopyToDataTable())
[/EDIT]