How can I allow null values to be saved?


Author
Message
Peter Jones
Peter Jones
Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)
Group: Forum Members
Posts: 386, Visits: 2.1K
Hi,

I have string field that is nullable in the database. In my BO I have AllowNullValuesOnNewRow set to True. In the BO Custom Field Properties I have Return Alternate on Null with the value being String.Empty. When a new row is created I don't set a default value for this field.

Ok - now here's the problem. When I create a new row and don't touch that field a Null is saved to the database (good). However, if I put something in that field and then blank it out then "" (empty string) is saved to the database (bad).

If I have an existing record with a value in the field and I blank it out it is also saved as an empty string when, in fact, I really want it saved as a Null.

Try as I may I just can't find the magic settings to achieve nulls. How do I go about saving null values instead of empty strings.

Cheers, Peter

Peter Jones
Peter Jones
Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)
Group: Forum Members
Posts: 386, Visits: 2.1K
ps

While my question is specific to string fields I also have date fields that I needs to be able to save as nulls. I pretty sure all our numeric fields default to zero.

Cheers, Peter

Jerome Barnett
Jerome Barnett
StrataFrame Beginner (18 reputation)StrataFrame Beginner (18 reputation)StrataFrame Beginner (18 reputation)StrataFrame Beginner (18 reputation)StrataFrame Beginner (18 reputation)StrataFrame Beginner (18 reputation)StrataFrame Beginner (18 reputation)StrataFrame Beginner (18 reputation)StrataFrame Beginner (18 reputation)
Group: Forum Members
Posts: 10, Visits: 65
In your post you said that you set "Return Alternate on Null". You need to set your property to "Return Alternate on Null / Set Null on Alternate"



Hope that helps



Jerome
StrataFrame Team
S
StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
Yep, Jerome is correct.  If you use the Return Alternate on NULL / Set NULL on Alternate, then setting the property to String.Empty will result in a DBNull.Value being put back into the DataTable by the property.  It's new functionality added by the latest 1.6 release, so if you don't have that option within the BOMapper, I would recommend downloading the latest SF version. 

The Set NULL on Alternate also works for reference types (INTs, FLOATs, etc.).

Peter Jones
Peter Jones
Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)
Group: Forum Members
Posts: 386, Visits: 2.1K
Hi Guys,

Thanks for that - in retrospect I can't believe I didn't try Return and Set.

Cheers, Peter

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