public static List<Dictionary<string, dynamic>> ToDict(this DataTable dt)
{
var tableDict = new List<Dictionary<string, dynamic>>();
foreach (DataRow row in dt.Rows)
{
var rowDict = new Dictionary<string, dynamic>();
foreach (DataColumn col in dt.Columns)
{
var fieldValue = row[col].Equals(DBNull.Value)
? null
: row[col];
rowDict.Add(col.ColumnName, fieldValue);
}
tableDict.Add(rowDict);
}
return tableDict;
}