My asp.net 4.0 application accepts user input to fill a form and stores the information in a Sql Server db. Email is automatically generated and sent to a set of predetermined users. Some of the information on the form is required (for example an equipmentType) and some is optional (for ex YearofMfg and equipmentModel). Both the required information and the optional information are included in the email.
My app properly collects the information from the db after the form is completed and sends the email. However my app does not handle the optional information properly. When the optional fields are left blank on input, I want the app to report them as "Not known" in the email. This is not happening. When the optional fields are not left blank, the emails are handled properly.
In fact, the two fields YearofMfg and equipmentModel seem to be handled differently, even though I have set them up similarly. Both fields allow nulls. When I use SS Management Studio (SSMS) to examine the db, both are shown as nulls for the records, as they should. However my mail send module, attached, leaves the equipmentModel field blank and crashes with an invalid cast when trying to use seemingly identical code to handle YearofMfg.