Question

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.

enter image description here

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!

Was it helpful?

Solution

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:

  • A Quote table, that will be used to tie the others together. This would include fields like a Vendor ID, Quote Number, etc.
  • A QuoteItems or QuoteProducts table, where each record in the table will store information for one "piece" in the quote. It will include information from your form like Quantity, PricePerPiece, Freight, and also information like Part Number, and Display Order/Line Number. You'll also need to keep the key field from your quote table here.
  • A CustomCharges table. This will include the key from the Quote table and the line number from the QuoteItems table, and also a ChargeDescription and ChargeAmount field. Optionally, these two fields could be added to the QuoteItems table instead.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top