Null value as a default value


Author
Message
Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
You are welcome dktiong.

Edhy Rijo

Diu King,Tiong
Diu King,Tiong
StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)
Group: Forum Members
Posts: 43, Visits: 264
Hi Edhy,

I did it with your solution and get what you mean, I will invest some of the time to read through the help file.


Thanks alot....
Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
dktiong (10/11/2010)
Hi Ehdy,

How do i default my value to topmostvalue if i don't choose anything from that combobox.


please advice


Based on your initial requirement, the value in the database will stay NULL, if you want to assign a default value, then in the Business Object there is a method SetDefaultValues() which you can use to just that.  I personally try to avoid NULL values in the database so in my table scripts I have a default value at the table level to avoid getting any NULLs.

It is very important when learning to use SF to invest some time in looking at the help file which is very well structure to be aware of what is available to you and also look at the sample code in the help and then search the forums using keywords like in this case I would use "default values" or something along those lines.  The forum is rich with many sample code from the community and the chances that a question from a starter SF developer has already being answer is very high.

Edhy Rijo

Diu King,Tiong
Diu King,Tiong
StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)
Group: Forum Members
Posts: 43, Visits: 264
Hi Ehdy,

How do i default my value to topmostvalue if i don't choose anything from that combobox.


please advice
Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi dktiong,

Glad you figured out.

Edhy Rijo

Diu King,Tiong
Diu King,Tiong
StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)
Group: Forum Members
Posts: 43, Visits: 264
Hi Edhy and Greg,

Thanks for ur solution. my question is same as the link http://forum.strataframe.net/Topic20554.aspx and it did help me.


Thanks again
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.4K 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.

Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Ok, then you must use the BO NULL Value Option as I explained before to force the NULL value back to the field.  Have you try that?

http://forum.strataframe.net/Uploads/Images/aa3f4111-28f4-4a8a-9397-047b.png

Edhy Rijo

Diu King,Tiong
Diu King,Tiong
StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)StrataFrame Novice (59 reputation)
Group: Forum Members
Posts: 43, Visits: 264
yes Edhy, i created the RI in MS-SQL. I need RI when i do the delete record. RI will search if deleted record got reference at others table then delete will not successful on that record.

Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
dktiong (10/8/2010)
I did set referential integrity for this relationship between purchase order and customer.
My problem is when i try to insert new record for purchase order and i didn't choose customer, suppose foreign key customer inside purchase order table is default to NULL. Strataframe framework do prompt me the message like "The insert statement conflicted with the foreign key constraints.........................."


Where did you set the referential integrity: in MS-SQL or in the StrataFrame (SF) Business Objects?

If you created the RI in MS-SQL, then delete it since using StrataFrame you really don't need it unless you will be adding records outside StrataFrame. SF handles the relationship via the Business Object where you can do as many relations as you want and also via code.

Edhy Rijo

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