StrataFrame Forum

How can I allow null values to be saved?

http://forum.strataframe.net/Topic8394.aspx

By Peter Jones - 4/20/2007

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

By Peter Jones - 4/20/2007

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

By Jerome Barnett - 4/23/2007

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
By StrataFrame Team - 4/23/2007

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.).

By Peter Jones - 4/23/2007

Hi Guys,

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

Cheers, Peter