How do I set a default value?


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'm obviously missing something pretty basic here but I can't see it. I have a table with a GUID as a PK. When I save a new record I get the error:

BusinessLayerException
 An error occurred while saving an the data to the server.
DataLayerSavingException
 Cannot insert the value NULL into column 'AGTID', table 'TMS201.dbo.tblAGTAttrGroupTypes'; column does not allow nulls. INSERT fails.
The statement has been terminated.
SqlException
 Cannot insert the value NULL into column 'AGTID', table 'TMS201.dbo.tblAGTAttrGroupTypes'; column does not allow nulls. INSERT fails.

However, in the BO I have the field set as per screen shot - note the screen shot also shows the property code for the column. I have tried setting the bo control value to "Return Alternate on Null" but the result is the same.

I also noticed that, when I create a new row, a checkbox for which I have a default value of 'True', is unticked on the new record. I was presuming that the defaults settings in the BO would take effect when a new is presented to the user for initial data entry - is this not so?

BTW my test form is using a DevEx grid.

Cheers, Peter

Replies
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,

Well I tested this out and it didn't seem to work. I have a field AGTName which allows Nulls and has no defaults. If I manually create a row in the database and don't key anything for AGTName the new row has a Null for this value. In my BO I set the Null Replacement Value to string.empty and I have no default set up for this column. In the Null Value Option property I have tried "Return Alternate on Null" plus the two new variations introduced in 1.6 and, whenever I create a new record and don't key anything into AGTName, I get an empty (not a Null) value in the database.

While on this subject can you please clarrify what the two new "Return Alternate on Null / xxx" properties do. I was assuming that if I select "../ Set Null on Alternate (reference type)" then, if the BO sees that the value being saved is the same as the value in "Return Alternate to Null" (in my case string.empty), then it would propergate Null back to the database. Is this correct?

Cheers, Peter

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
The problem isn't with your configuring of your field.  A business object has a "blanket" property that prevents any NULL values from new records within the business object.  It's called AllowNullValuesOnNewRow, and it defaults to False.  When it's False, the business object will initialize all columns of a new row to be the .NET default values for the data types (except System.String, which is set to String.Empty rather than Nothing (C# null)).  So, if you set that AllowNullValuesOnNewRow property to True, then when you add a new row to the business object, the column values will be left at DBNull.Value.
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