C# DataTable 转lList>

 

 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;
        }

 

上一篇:数据库基础面试题-SQL语句


下一篇:Flutter DataTable 看这一篇就够了