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)转键值对集合

 

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

上一篇:VMware安装Windows Server 2008


下一篇:jQuery基本选择 元素