Selasa, 19 Februari 2008

Serialize Dataset Using Binary Formatter and XML

How to Serialize to XMl
MyDataSet.writexml(path,xmlwritemode.ignoreschema)
If you want to keep the original datarow object information for later syncrhonized with database
MyDataSet.writexml(path,xmlwritemode.Diffgram)
DiffGram contains all of the DataRowVersion information as shown in the following XML

How to DeSerialize from XMl
MyDataSet.Readxml(path,xmlreadmode.Ignoreschema);
MyDataSet.Readxml(path,xmlreadmode.Diffgram);

How to Serialize to Binary
FileStream fs=new FileStream(
@"c:\MyDataset.bin",FileMode.Create);
BinaryFormatter fmt= newBinaryFormatter();
fmt.Serialize(fs, MyDataset);
fs.Close();

How to Deserialize from Binary
DataSetvendorData;
FileStream fs=new FileStream(
@"c:\MyDataset.bin", FileMode.Open);
BinaryFormatter fmt= newBinaryFormatter();
MyDataset=(DataSet)fmt.Deserialize(fs);
fs.Close();

Tidak ada komentar: