C#数据表(DataTable)转键值对集合


/// <summary> /// 数据表转键值对集合 /// 把DataTable转成 List集合, 存每一行 /// 集合中放的是键值对字典,存每一列 ,键/值相同 /// </summary> /// <param name="dt">数据表</param> /// <returns>哈希表数组</returns> public static List<Dictionary<string, object>> DataToList(DataTable dt) { List<Dictionary<string, object>> list = new List<Dictionary<string, object>>(); foreach (DataRow dr in dt.Rows) { Dictionary<string, object> dic = new Dictionary<string, object>(); foreach (DataColumn dc in dt.Columns) { dic.Add(dc.ColumnName, dr[dc.ColumnName]); } list.Add(dic); } return list; }

C#数据表(DataTable)转键值对集合

 

 转换成C#数据表(DataTable)转键值对集合

 

上一篇:dataTable input可修改、select可选择列,操作中带上传文件


下一篇:DataTable转List,DataTable转为Model对象帮助类