Is there a standard way of doing this? I had considered using XML, but perhaps there is a more straight-forward way.
To clarify, I'm d开发者_C百科umping the whole collection in a "details" column in my database - I do parse some but want to keep an archive of the whole set. I was able to get SoapFormatter to work fine, though this is a bit heavy.
I would probably go about this by storing the NameValue pair as a name value pair in the DB.
ie. Have a table with a Name and Value Column (Maybe a Primary Key ID if names arent unique) then foreach item in your collection you can insert a row.
Retrieving it would be as easy as selecting where the Name is whatever name you want to get the value for.
One option is serialize your NameValueCollection and save the byte[] in the database. You can use either XML serialization or BinaryFormatter.
A Table with two columns. FirstColumn : Key for the log SecondColumn : Value (Serialized Log which has namevalueCollection).
Edit:
If the value is just text. Save that it as it is. No need to serialize or convert to xml I think. In the first column save the key and save the value in the second column.
精彩评论