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

Thanks for the comment. I wonder then, if the developer has to hand code defaults what purpose does the "null value option" serve - maybe I've misunderstood how that is used within SF.

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
Greg is right on the SetDefaultValues() method.  For GUID pks, you either have to set NEWID() as the default value for the column within SQL Server (but the newly assigned GUID will not be retrieved on a save), create a stored procedure for INSERTs that will return the new GUID in an output parameter, or set the AGTID field within the SetDefaultValues() method to Guid.NewGuid(). 

As for the "Null value options" they are in place because ADO.NET represents null database values with DBNull.Value, and the DBNull type cannot be converted to any other data type (save object), and so when you access the get of a field property that has a null, you will get an InvalidCastException.  So, if you want your database to allow null values, then you will need to configure the fields that you want to allow null values to return some other value when a DBNull.Value is encountered.

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