C# 格式转换--list 转 DataSet

2021-01-23 20:15

阅读:793

标签:oar   row   static   tac   var   oda   格式   pre   ddr   

//将list转成DataSet

public static DataSet ListToDataSet(List list)
{
if (list.Count == 0) return new DataSet();
var properties = list[0].GetType().GetProperties();
var cols = properties.Select(p => new DataColumn(p.Name));
var dt = new DataTable();
dt.Columns.AddRange(cols.ToArray());
list.ForEach(x => dt.Rows.Add(properties.Select(p => p.GetValue(x)).ToArray()));
return new DataSet { Tables = { dt } };
}

 

C# 格式转换--list 转 DataSet

标签:oar   row   static   tac   var   oda   格式   pre   ddr   

原文地址:https://www.cnblogs.com/quwujin/p/12066908.html


评论


亲,登录后才可以留言!