DataTable 转为 List<dynamic>

 

static List<dynamic> DataTableToListDynamic(DataTable dt)
{
List<dynamic> dynamicList = new List<dynamic>();

foreach (DataRow row in dt.Rows)
{
dynamic dynamicObj = new ExpandoObject();
var expandoDict = (IDictionary<string, object>)dynamicObj;
foreach (DataColumn column in dt.Columns)
{
expandoDict[column.ColumnName] = row[column];
}
dynamicList.Add(dynamicObj);
}

return dynamicList;
}

 

 

static List<dynamic> DataTableToListDynamic(DataTable dt)
{
List<dynamic> dynamicList = new List<dynamic>();

foreach (DataRow row in dt.Rows)
{
dynamic dynamicObj = new ExpandoObject();
var expandoDict = (IDictionary<string, object>)dynamicObj;
foreach (DataColumn column in dt.Columns)
{
expandoDict[column.ColumnName] = row[column];
}
dynamicList.Add(dynamicObj);
}

return dynamicList;
}

posted @ 2024-03-24 19:47  LowKeyC  阅读(90)  评论(0编辑  收藏  举报
有志者事竟成破釜沉舟百二秦关终属楚苦心人,天不负,卧薪尝胆,三千越甲可吞吴