I have a populated DataTable I'd like to serialize to a file for later use. I've been looking over the options involved with this and wondered if someone could point me in the right direction.
What I'll be creating are two methods-- one for writing the datatable to a file, and another for creating a new datatable using the file as input. Does it make sense to use the WriteXML() and Load() methods to do this, and if so, which flag(s) are ones to focus on? Thanks for the guidance.
I'm using .Net 2.0 if that helps.
I think Silveira comment mean use of binary serialization. And its right that it very fast compare to XML which serialization is very slow compare to binary specially for large amount of data. Also it take a lot less space on disk compare to XML.
public static void Serialize(DataSet ds, Stream stream) {
BinaryFormatter serializer = new BinaryFormatter();
serializer.Serialize(stream, ds);
}
public static DataSet Deserialize(Stream stream) {
BinaryFormatter serializer = new BinaryFormatter();
return (DataSet)serializer.Deserialize(stream);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With