Using a System.Int32 and null values


Author
Message
Lesscher
Lesscher
StrataFrame Beginner (13 reputation)StrataFrame Beginner (13 reputation)StrataFrame Beginner (13 reputation)StrataFrame Beginner (13 reputation)StrataFrame Beginner (13 reputation)StrataFrame Beginner (13 reputation)StrataFrame Beginner (13 reputation)StrataFrame Beginner (13 reputation)StrataFrame Beginner (13 reputation)
Group: StrataFrame Users
Posts: 9, Visits: 19
Hi all,

I have several fields in my table of type System.Int32 and they are allowed to be null. I want to put a NULL value (not a 0) in the database table when the user empties a textbox (bound to the BO).

I already read the posts about this solution using String.Empty but thats not working for me... Also, I tried to use nullable generics in the datamapper but then, when the user empties the textbox, the new (empty) value isn't saved to the BO (the old value remains)

This can't be that difficult, am I right?

Reply
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (4.8K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Lesscher,



Another approach would be to create a subclassed text box that alters the Text property and handles the Text property being empty when setting the underlying value. You'd leave the BO setup to return an alternate value for Null/Save Null on that alternate value (zero in this case). This makes any programmatic access to the data easier, as integers don't have NULL as a possibility.



I did this for the case of identities. If the ID is <0 (i.e. a new value), it displays "(new)", otherwise it displays the actual ID.



I overwrote the Text property. The setter just sets the Text property on the base class. The getter tests the value of the base class and simply displays something different if the number is negative.



I'd think you'd need to add some code to the setter, to set a "0" to the base class if the text is blank. And in the getter, you'd test for zero, displaying a blank in that case, otherwise whatever they have entered.



Hope that helps!



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