Null Values


Author
Message
Jim Schepflin
Jim Schepflin
StrataFrame Novice (95 reputation)StrataFrame Novice (95 reputation)StrataFrame Novice (95 reputation)StrataFrame Novice (95 reputation)StrataFrame Novice (95 reputation)StrataFrame Novice (95 reputation)StrataFrame Novice (95 reputation)StrataFrame Novice (95 reputation)StrataFrame Novice (95 reputation)
Group: Forum Members
Posts: 25, Visits: 64
How is it recommended to deal with nulls?



I have fields that don't have an invalid value, and would like null to be used for these fields, IF the user does not set them



Hoping to allow this, if not, then I need to code up an extra field for each nullable value indicating "Value really set" or some such, that would be a pain.



Example is a field Daily Usage, I would like the user to be able to enter any value they wish, or to clear the value to indicate that they haven't determined it.



Getting a bunch of errors, and defaulting a Decimal to 0 will negate this option, wouldn't it?



Looking for ideas, really, at this point.



Might be due to the use of a numeric control (NumericUpDown), but seemed the "correct" control to use rather than a text box, not sure if the text box would allow nulls





If I set it to Return Alternate on Null, default value of 0, seems to work (run, but don't get the null I desire)

If set to Use Nullable Generic, then get "An error occurred while refreshing the data from field 'Hier_DataBO.DailySales' to property 'Value' on control 'numDailySales.'"

If I set to not allow nulls, get (when press edit) "Specified cast is not valid." in the field, since it defaulted to null



So seeming more and more that the numeric control just won't work with nullable values...
StrataFrame Team
S
StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
Your best bet would probably be to go back to using the Nullable generic for the field.  However, you will need to customize the properties on the NumericUpDown control after the binding is added (after the form's Load fires) and change the properties on the binding like so:

NumericUpDown1.DataBindings(0).?

You'll need to specify the DataSourceNullValue as a Nullable generic value of null and set the NullValue to whatever value within the numeric up down should be considered a null value.

Jim Schepflin
Jim Schepflin
StrataFrame Novice (95 reputation)StrataFrame Novice (95 reputation)StrataFrame Novice (95 reputation)StrataFrame Novice (95 reputation)StrataFrame Novice (95 reputation)StrataFrame Novice (95 reputation)StrataFrame Novice (95 reputation)StrataFrame Novice (95 reputation)StrataFrame Novice (95 reputation)
Group: Forum Members
Posts: 25, Visits: 64
Ok, tried that, temp was to set it to -1 for the moment

Hooked that into the business object



Now fails in trying to load the data, through a custom fill method -



An error occurred while refreshing the data from field 'Hier_DataBO.DailySales' to property 'Value' on control 'numDailySales.'



Based heavily on code already in the forums, pulling by the primary key:

loCommand.CommandText = "Select * from " + this.TableNameAndSchema + " Where HierDataKey = @HierDataKey";

// Create the Parameters

loCommand.Parameters.Add("@HierDataKey", SqlDbType.VarChar);

// Set the Parameters

loCommand.Parameters["@HierDataKey"].Value = lHierDataKey;

// Fill the business object using the command

this.FillDataTable(loCommand);





Error occurs on the FillDataTable, doesn't even get to the newrow.

Primary key is a GUID, which is why I'm not using the built-in primary key field



This is with the BO field set to Use Nullable Generic, and having re-built the partial from that.



Targetsite of the exception:

{Void RefreshControl(MicroFour.StrataFrame.UI.Windows.Forms.IBusinessBindable, Boolean)}
StrataFrame Team
S
StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
The error isn't coming from the actual fill... it's coming from the business object will refresh all of its bound controls after it is done filling.  The refresh is causing the error because the binding still isn't configured.

Most likely, the error is coming from the NumericUpDown... if you set the NullValue to -1, it will try to set the value within the control to -1 and if -1 is outside of the range of possible values, then it will fail.

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search