I am writing a .net application that is taking form information to do some car loan prequalification calculations and will store this in a database. The trouble is every field should allow the user to type any kind of string data into it and preserve it into the database.
Most of the fields need to be converted to decimal or integer values to do any calculation so is it best to just ignore the data type and use strings in the database?
I haven’t tested this approach but I would expect it to be difficult to find and sort the data correctly with this approach since every thing would be a string and need to be converted to the real data type to do a query.
One other alternative I have considered is to have two columns for every field one to hold the string value and one to hold the actual parsed value type. This sounds some what difficult to maintain.
lastly I have thought about storing one extra column or table that will just be a name value pair to put all the unparsable data for that record. I think this may be very difficult to create business objects against.
How do you tend to to deal with this type of issue?
I think your suggestion of using two columns for every field is the best approach. After all this is semantically what is happening.
When the user enters an amount, you want to store what the user typed and the actual amount so you’ll need two fields.
When you create your application, make sure you group all data access together. This way you can make this solution maintainable.