tags:

views:

43

answers:

1

hello,

im tasked to create a virtual database that clients can create from our web application and have them save data to.

the problem now is to have it stored for later re-use.

im thinking of dynamically creating a DataTable object in c# then convert it to byte[]. now i want to know if this would be practical to save on a database...

is this possible?

A: 

You can use WriteXml to write to a stream:

byte[] raw;
using(MemoryStream ms = new MemoryStream()) {
    table.WriteXml(ms);
    raw = ms.ToArray();
}
...
raw = ...
using(MemoryStream ms = new MemoryStream(raw)) {
    table.ReadXml(ms);
}

And write the byte[] to a varbinary(max) / image / etc column in a database if that is what you need (you mentioned database) - or just use xml.

If you are writing to a file, then just use a FileStream in place of a MemoryStream.

Marc Gravell