代码
private static string SerializeDataTableXml(DataTable pDt)
{
// 序列化DataTable
StringBuilder sb = new StringBuilder();
XmlWriter writer = XmlWriter.Create(sb);
XmlSerializer serializer = new XmlSerializer(typeof(DataTable));
serializer.Serialize(writer, pDt);
writer.Close();
return sb.ToString();
}
public static DataTable DeserializeDataTable(string pXml)
{
StringReader strReader = new StringReader(pXml);
XmlReader xmlReader = XmlReader.Create(strReader);
XmlSerializer serializer = new XmlSerializer(typeof(DataTable));
DataTable dt = serializer.Deserialize(xmlReader) as DataTable;
return dt;
}
{
// 序列化DataTable
StringBuilder sb = new StringBuilder();
XmlWriter writer = XmlWriter.Create(sb);
XmlSerializer serializer = new XmlSerializer(typeof(DataTable));
serializer.Serialize(writer, pDt);
writer.Close();
return sb.ToString();
}
public static DataTable DeserializeDataTable(string pXml)
{
StringReader strReader = new StringReader(pXml);
XmlReader xmlReader = XmlReader.Create(strReader);
XmlSerializer serializer = new XmlSerializer(typeof(DataTable));
DataTable dt = serializer.Deserialize(xmlReader) as DataTable;
return dt;
}