DataTable转List(备忘)

public static List ToList(DataTable dt)
{
  List<Dictionary<string, object>> list = new List<Dictionary<string, object>>();
  foreach (DataRow dr in dt.Rows)
  {
    Dictionary<string, object> result = new Dictionary<string, object>();
    foreach (DataColumn dc in dt.Columns)
    {
      result.Add(dc.ColumnName, dr[dc]);
    }
    list.Add(result);
  }
  return list;
}

 

posted @ 2015-08-19 09:32  Ciel Water  阅读(169)  评论(0编辑  收藏  举报