DataTable的序列化与反序列化.

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

你可能感兴趣的:(DataTable的序列化与反序列化.)