public static Dictionary<string, object> ToJson(DataTable table) { Dictionary<string, object> j = new Dictionary<string, object>(); j.Add(table.TableName, RowsToDictionary(table)); return j; } private static List<Dictionary<string, object>> RowsToDictionary(DataTable table) { List<Dictionary<string, object>> objs = new List<Dictionary<string, object>>(); foreach (DataRow dr in table.Rows) { Dictionary<string, object> drow = new Dictionary<string, object>(); for (int i = 0; i < table.Columns.Count; i++) { drow.Add(table.Columns[i].ColumnName, dr[i]); } objs.Add(drow); } return objs; }
RowsToDictionary
DataTable
ToJson
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)