0

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!

5
  • why an array? that looks like there could be several classes (Vendor, Product...) related to a larger Quote class. These could then be easily serialized. Same goes for a DB those look like they relate to several tables. Since the data is mixed types (String, Integer and Decimal), an array seems a bad idea. Commented May 13, 2014 at 13:41
  • So categorize these into the different types (Vebder, Product etc) serialize that information and store them into respective db columns? Commented May 13, 2014 at 13:44
  • 2
    Grouping all that data into a single column would be horrible. It's the wrong way to use a database. Commented May 13, 2014 at 13:44
  • a (properly designed and normalized) db is much better for permanent storage of many Quotes. Serialization would be ok for a few quotes which are being sent somewhere for some reason (submit for approval etc) Commented May 13, 2014 at 13:49
  • I see what you guys are saying. Ill scratch this and setup a relational db instead. Would make things alot easier to manage. Thanks guys! Commented May 13, 2014 at 13:52

1 Answer 1

1

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.
Sign up to request clarification or add additional context in comments.

2 Comments

Fantastic answer thank you! Ive only had to create two or three databases personally before and never really got the relational aspect of it down. Ill stick to this model for the rest of the application!
I was able to setup a relational db based on your instructions. Thank you again! microdotech.com/wp-content/uploads/2014/05/… And thanks for not being harsh on us new guys!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.