1 /// <summary>
2 /// 序列化DataTable
3 /// </summary>
4 /// <param name="pDt">包含数据的DataTable</param>
5 /// <returns>序列化的DataTable</returns>
6 private static string SerializeDataTableXml(DataTable pDt) {
7 // 序列化DataTable
8 StringBuilder sb = new StringBuilder();
9 XmlWriter writer = XmlWriter.Create(sb);
10 XmlSerializer serializer = new XmlSerializer(typeof(DataTable));
11 serializer.Serialize(writer, pDt);
12 writer.Close();
13
14 return sb.ToString();
15 }
16
2 /// 序列化DataTable
3 /// </summary>
4 /// <param name="pDt">包含数据的DataTable</param>
5 /// <returns>序列化的DataTable</returns>
6 private static string SerializeDataTableXml(DataTable pDt) {
7 // 序列化DataTable
8 StringBuilder sb = new StringBuilder();
9 XmlWriter writer = XmlWriter.Create(sb);
10 XmlSerializer serializer = new XmlSerializer(typeof(DataTable));
11 serializer.Serialize(writer, pDt);
12 writer.Close();
13
14 return sb.ToString();
15 }
16
1 /// <summary>
2 /// 反序列化DataTable
3 /// </summary>
4 /// <param name="pXml">序列化的DataTable</param>
5 /// <returns>DataTable</returns>
6 public static DataTable DeserializeDataTable(string pXml) {
7
8 StringReader strReader = new StringReader(pXml);
9 XmlReader xmlReader = XmlReader.Create(strReader);
10 XmlSerializer serializer = new XmlSerializer(typeof(DataTable));
11
12 DataTable dt = serializer.Deserialize(xmlReader) as DataTable;
13
14 return dt;
15 }
16