Null value as a default value


Author
Message
Diu King,Tiong
Diu King,Tiong
StrataFrame Novice (81 reputation)StrataFrame Novice (81 reputation)StrataFrame Novice (81 reputation)StrataFrame Novice (81 reputation)StrataFrame Novice (81 reputation)StrataFrame Novice (81 reputation)StrataFrame Novice (81 reputation)StrataFrame Novice (81 reputation)StrataFrame Novice (81 reputation)
Group: Forum Members
Posts: 43, Visits: 264
Hi all,

Initially i set my foreign key's field's column properties's Default value or Binding to 0. After while i want back Null values to be saved and i remove 0 from Default value or Binding. However still default value 0 but not Null values saved.

Please advice...
Reply
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (4.8K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Hi dktiong,

I'll add to what Edhy has already stated, as there still seems to be some confusion.  I'm guessing that you are using key fields that have a data type of int.   If you do customization of this sort of field in the BO Mapper, it will default to a value of zero, because in .NET an int must have a value and it defaults to zero.  In the database, it can be null and in fact needs to be null for RI to work.

The solution is to setup the field to return/set an alternate value for nulls. This means that the when the value in the database is NULL, you can setup the BO to return another value, like zero.  And if the value of a field in the BO is zero when saved, a NULL actually gets saved to the database.  When doing this you also don't need to set any default as essentially NULL is default in database and zero is default for ints in .NET.  Likely you got the message because you were setting the value to zero and there were no customers with a Key of zero.  Using what I'm talking about, the value would set to null if no customer is set and the db can understand that.

If you use a combobox to allow the selection of the FK value, you'd need to use the TopMostValue property, setting the value to whatever you are returning for null (zero in this example) and you can set some text indicating no FK has been selected.

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