C# DataTable 转lList<Dictionary<string, string>>
作者:互联网
public List<Dictionary<string, string>> DataTableToList(DataTable dt) { List<Dictionary<string, string>> result = new List<Dictionary<string, string>>(); if (dt != null && dt.Rows.Count > 0) { foreach (DataRow dr in dt.Rows) { Dictionary<string, string> dic = new Dictionary<string, string>(); for (int i = 0; i < dr.Table.Columns.Count; i++) { dic.Add(dr.Table.Columns[i].ColumnName.ToString(), dr[dr.Table.Columns[i].ColumnName].ToString()); } result.Add(dic); } } return result; }
标签:C#,List,dic,lList,result,dt,dr,DataTable,Columns 来源: https://www.cnblogs.com/fenghaolei/p/12574924.html