1.DataSet的序列化
SqlConnection con = new SqlConnection(ConfigurationSettings.AppSettings.Get("Con"));
SqlDataAdapter adp = new SqlDataAdapter("select * from tbl_Copy",con);
DataSet ds = new DataSet();
adp.Fill(ds);
gridControl1.DataSource = ds.Tables[0].DefaultView;
FileStream fs = new FileStream("C://DataSet.txt",FileMode.Create);
BinaryFormatter bf = new BinaryFormatter();
ds.RemotingFormat = SerializationFormat.Binary;
//ds.RemotingFormat = SerializationFormat.Xml;
DateTime sTime = DateTime.Now;
bf.Serialize(fs, ds);
DateTime eTime = DateTime.Now;
TimeSpan ss = eTime.Subtract(sTime);
label1.Text = "序列化10万条数据,用时:" +ss.Seconds+"."+ss.Milliseconds+"秒";
//默认是XML的序列化格式
//Binary格式
//0.5秒
//DataSet.txt 3.21MB
//XML格式
//1.593 秒、1.602 秒,基本上1.6秒快三倍多
//XML.txt 11.4 MB 是二进制的大约3倍
2.DataSet的反序列化
FileStream fs = new FileStream("C://DataSet.txt", FileMode.Open);
BinaryFormatter bf = new BinaryFormatter();
bf.Deserialize(fs);