If you need to store an entire object for later use, that's Serialization.
Using something like Fastest way to serialize and deserialize .NET objects you create three components:
- Code to convert the Table into a string (or binary)
- Code to exactly reverse the conversion from step 1. so you can reuse the object
- Some place to store the string (or binary) data.
The code is simply
public static string Serialize(Table table)
{
var serializer = new XmlSerializer(typeof(Table));
TextWriter writer = new StringWriter();
serializer.Serialize(writer, table);
return writer.ToString();
}
public static Table Deserialize(string tableData)
{
var serializer = new XmlSerializer(typeof(Table));
TextReader reader = new StringReader(tableData);
return (Table)serializer.Deserialize(reader);
}
You can put this data into a SQL Server varchar(max)
column, obviously with some primary key so you can later retrieve it.