Is there an easy way to store an array in a single column in a SQL Server CE database?

I examined the possible answers here (for PHP, I think): http://www.lateralcode.com/store-array-database/ , but I can not find the serialization / deserialization version of C # .net.

Will this be done the same way as shown in my link above, or is there a completely different approach that I should use, given the environment?

I just don’t want to have a bunch of different columns for each of 12 values ​​in each of 9 different arrays, so if there is a different approach to achieving this (converting to byte [], etc.), I am more than willing to hear this.

If that helps, the arrays will be simple string [] arrays.

+7
source share
3 answers

Convert an array of strings to a single string, as shown below:

var a = String.Join(",",arrays); //or aim is to provide a unique separator, //ie which won't be the part of string values itself. var a= String.Join("~~",arrays); 

and return it like this:

 var arr = a.Split(','); //or split via multiple character var arr = a.Split(new string[] { "~~" }, StringSplitOptions.None); 
+6
source

Try to serialize the array and create a column in a Blob-type database 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); 
+1
source

I just don’t want to have a bunch of different columns for each of 12 values ​​in each of 9 different arrays, so if there is another approach to achieve this (conversion to bytes [], etc.). I am more than wanting to hear it.

From the description above, it looks like you are using an RDBMS.

The fact that you want to keep multiple values ​​in one column yells about a design problem.

I agree that having separate columns may not be able to, especially if the number of elements in each array can potentially change in the future.

Consider splitting this data into a separate table and mapping from 1 to many with your original table with a foreign key relationship

+1
source

All Articles