Reputation: 791
I have a vb.net form that accepts about 50 inputs from the user. I need to be able to take that information and store it into a database. Coming from a PHP background i looked at serializing a multidimensional array and storing all of the fields into a single db column instead of creating 50 something db columns.
I have successfully serialized an arrayList of the fields and am able to both serialize and deserialize it back into an arrayList.
Public Function SerializeArraylist(ByVal arraylst As ArrayList) As String
Dim bf As New Runtime.Serialization.Formatters.Binary.BinaryFormatter
Dim mem As New IO.MemoryStream
bf.Serialize(mem, arraylst)
Return Convert.ToBase64String(mem.ToArray())
End Function
'Deserialize
Public Function DeserializeArraylist(ByVal arraystring As String) As ArrayList
Dim bf As New Runtime.Serialization.Formatters.Binary.BinaryFormatter
Dim mem As New IO.MemoryStream(Convert.FromBase64String(arraystring))
Return DirectCast(bf.Deserialize(mem), ArrayList)
End Function
However I see some major problems with this. One its pretty messy and would make alot more sense to store the information in a multidimensional array to better organize the data. Ive looked around and have not been able to come up with a solution. There is this topic: What Class for Serializable Multidimensional Arrays? but i cant seem to apply it to my situation.
With all that said my ultimate goal is to serialize a multidimensional array that i can store in a database then de-serialize it later down the road. However if there is a better way to handle this Im always open to trying something different!
Upvotes: 0
Views: 1503
Reputation: 415735
Grouping all that data into a single column would be horrible. It's the wrong way to use a database. You actually want multiple tables here. We don't have the complete picture from that screenshot, but from what we can see, you need something like this:
Upvotes: 1