日期:2014-05-18 浏览次数:20895 次
[Serializable] public partial class MyDataSet : DataSet, ISerializable { public MyDataSet() { } protected MyDataSet(SerializationInfo info, StreamingContext context) {} } private void btn反序列化_Click(object sender, EventArgs e) { byte[] buffer = null; IFormatter formater = new BinaryFormatter(); MemoryStream ms = new MemoryStream(); MemoryStream fs = new MemoryStream(); DataTable dt=dsSYS_TestM.Tables[0].Copy(); MyDataSet md = new MyDataSet(); md.Tables.Add(dt); formater.Serialize(ms, md); buffer = new byte[(int)ms.Length]; ms.Position = 0; ms.Read(buffer, 0, (int)ms.Length); ms.Close(); IFormatter bina = new BinaryFormatter(); MemoryStream ms1 = new MemoryStream(buffer); MyDataSet d = (MyDataSet)bina.Deserialize(ms1); ms1.Close(); }