Datatable与xml的互转

用于备忘,转自:https://blog.csdn.net/u012803075/article/details/53893367

DataTable转Xml

StringBuilder xml = new StringBuilder();
XmlWriter writer = XmlWriter.Create(xml);
XmlSerializer serializer = new XmlSerializer(typeof(DataTable));
serializer.Serialize(writer, dt);
writer.Close();
xml.ToString();

Xml转DataTable

DataSet dss = new DataSet();
dss.ReadXml(new StringReader(xml.ToString()));

你可能感兴趣的:(xml)