Problem:
There was a time in my project when I needed to serialize and deserialize my dataset object. Look at the options available for doing it. Normally you can do it as xml or binary.
Impact:
I thought that it would be good to go for binary because size of xml file produced can cause sometimes problems with resources like memory, bandwith etc. But then binary files contain more initial overhead compared to xml files.
Solution:
So after looking at pros and conns of both and my requirement I decided to go with xml serialization.
So here is the code to perform serialization of dataset objects as xml
DataSet ds = new DataSet();
//populate the dataset using data tables
//code for populating is not included here
ds.WriteXml(MapPath("File.xml"));
You can also regulate how the data is written to xml
by using ColumnMapping property of DataColumn object
Now to Deserialize you can perform follwing task
DataSet ds = new DataSet();
ds.ReadXml(MapPath("File.xml"));
gridview1.DataSource = ds;
gridview1.DataMember = "TabName";
gridview1.DataBind();
No comments:
Post a Comment