Split a DataTable into 2 or more DataTables based on Column value

后端 未结 2 632
执笔经年
执笔经年 2020-12-06 05:27

I have a DataTable called \"DTHead\" which has the following records,

 MIVID      Quantity         Value
------     ----------       --------
   1                    


        
2条回答
  •  悲&欢浪女
    2020-12-06 06:20

    Use LINQ to DataTable to group the first column by GroupBy, and use method CopyToDataTable to copy list of rows to DataTable

     List result = DTHead.AsEnumerable()
                .GroupBy(row => row.Field("MIVID"))
                .Select(g => g.CopyToDataTable())
                .ToList();
    

    Then you can get the result as a list of DataTables as you expected.

提交回复
热议问题