1. 程式人生 > >xml與datatable互轉

xml與datatable互轉

DataTable轉Xml --dt為已獲得的DataTable

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轉 xml為上面的xml變數
DataSet dss = new DataSet();
dss.ReadXml(new StringReader(xml.ToString()));