You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
IEnumerable<IGrouping<string,DataRow>> groupResult = dt.Rows.Cast<DataRow>().OrderBy<DataRow,string>(dr => dr["type"].ToString()).GroupBy<DataRow,string>(dr => dr["type"].ToString());
var groupList = new List<object>();
foreach (IGrouping<string,DataRow> gr in groupResult)
{
// 获取当前分组数据
var groupType = gr.Key;
var groupListItem = new List<object>();
foreach (var dr in gr)
{
var row = new
{
id = dr["id"].ToString(),
name = dr["name"].ToString()
};
groupListItem.Add(row);
}
groupList.Add(new
{
groupType,
groupListItem
});
}
完
The text was updated successfully, but these errors were encountered:
前言
现在都流行匿名类,很少创建实体对象。当 DataTable 数据需要进行分组查询时,还是比较繁琐的。
DataTable 数据结构
将DataTable 数据根据 type 字段分组
完
The text was updated successfully, but these errors were encountered: