public static string JavaScriptSerialize(DataTable
dt)
{
JavaScriptSerializer ser = new JavaScriptSerializer();
List<Dictionary<string, object>>
rows = new List<Dictionary<string,
object>>();
Dictionary<string,
object> row;
foreach (DataRow
dr in dt.Rows)
{
row = new Dictionary<string, object>();
foreach (DataColumn
col in dt.Columns)
{
row.Add(col.ColumnName, dr[col]);
}
rows.Add(row);
}
return ser.Serialize(rows);
}
No comments:
Post a Comment