Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

serializing a datatable for later reuse

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.

like image 985
larryq Avatar asked Jan 12 '10 23:01

larryq


1 Answers

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);
    } 
like image 124
particle Avatar answered Sep 27 '22 16:09

particle