Group: Forum Members
Posts: 1,
Visits: 17
|
I'm working in WinForms in a maintenance form and with a MaintenanceFormToolStrip I'm trying to implement an 'Add' functionality to create a record in a table. I am encountering the following issue and would like to know if StrataFrame includes tools for handling such a case, or if not, a way it might be handled.
Conversion from type 'DBNull' to type 'String' is not valid.
Here's what's happening: Our form needs the ability to Add/Edit a table for which a non-integer primary key, which is not automatically generated, must be supplied on add. On read/edit, the key can be viewed but not changed.
I have created a StrataFrame TextBox and bound the field to it using the BusinessObject and BindingField properties of the TextBox, like I have done for the rest of the fields using the BO. However, when I click the Add button in the tool strip, I receive the error. Normally there should not be this problem on an Add because the primary key is usually automatically generated, but in this case it must be supplied manually by entering it in the TextBox. I'm guessing that the error is occurring because the BO is attempting to locate a record by the PK bound to the TextBox, but it doesn't exist yet. I mostly get this and why it occurs (to be sure not to add a dup PK?), but need a way around it.
I've tried not binding the TextBox to the BO and that works as I'd expect by not erroring, but then I lose all my automatic handling of validation and I still have to make sure it gets added to the BO on Save (correct?). Also I'd need to figure out how to account for differentiating between an Add and Edit type save operation and make sure I'm only using this logic on Add since an Edit won't alter a PK anyway. I'm not liking this and am not sure it will even work at the end so I'm hoping there's a better way using some framework magic. The initial plan is to do all this work in the ToolStrip.ItemClicked event but I'm sure that's not ideal either.
Any insight is appreciated! Thanks.
|