这段代码一直记着,他是我研究DataSet,DataTable,XML的开始
DataSet dataSet = new DataSet("dataSet");
DataTable table = dataSet.Tables.Add("Items");
table.Columns.Add("id", typeof(int));
table.Columns.Add("Item", typeof(string));
DataRow row;
for (int i = 0; i < 3; i++)
{
row = table.NewRow();
row["id"] = i;
row["Item"] = "Item" + i;
table.Rows.Add(row);
}
Console.WriteLine(dataSet.GetXml());
结果:<dataSet>
<Items>
<id>0<id>
<Item>Item0</Item>
<Items>
<Items>
<id>1<id>
<Item>Item1</Item>
<Items>
<Items>
<id>2<id>
<Item>Item2</Item>
<Items>
<dataSet>