Serialize a DataSet

Serialize a DataSet c#

DataSet dataSet = new DataSet("ds");
dataSet.Namespace = "NetFrameWork";
DataTable table = new DataTable();
DataColumn idColumn = new DataColumn("id", typeof(int));
idColumn.AutoIncrement = true;

DataColumn itemColumn = new DataColumn("item");
table.Columns.Add(idColumn);
table.Columns.Add(itemColumn);
dataSet.Tables.Add(table);

for (int i = 0; i < 2; i++)
{
    DataRow newRow = table.NewRow();
    newRow["item"] = "item " + i;
    table.Rows.Add(newRow);
}

dataSet.AcceptChanges();

string json = JsonConvert.SerializeObject(dataSet, Formatting.Indented);

Console.WriteLine(json);

2020-03-31