I have reviewed possible answers here (for PHP, I think): http://www.lateralcode.com/store-array-database/ but I am unable to find a C#.net version of serialize/deserialize.
Would this be done the same as the way shown in my link, above, or is there a completely different approach I should be using, given the environment?
I just don't want to have a bunch of different columns for each of the 12 values in each of my 9 different arrays, so if there is another approach to achieve this (converting to byte[], etc.) I am more than willing to hear it.
If it helps any, the arrays will be simple string[] arrays.
Convert your string array into single String like given below:
var a = String.Join(",",arrays);
//or aim is to provide a unique separator,
//i.e which won't be the part of string values itself.
var a= String.Join("~~",arrays);
and fetch it back like this:
var arr = a.Split(',');
//or split via multiple character
var arr = a.Split(new string[] { "~~" }, StringSplitOptions.None);
Try this to seralize the array and create a column in the database of type Blob to store the byte array.
Serialization:
if(array == null)
return null;
BinaryFormatter bf = new BinaryFormatter();
MemoryStream ms = new MemoryStream();
bf.Serialize(ms, array);
Deserialization:
String[] array = new String[10];
BinaryFormatter bf = new BinaryFormatter();
ms.Position = 0;
array = (String[])bf.Deserialize(ms);
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