StrataFrame Forum

Handling null value

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

By Chan - 1/30/2007

Hi,

I have a table with 3 fields



Field Name Type ALlow NULL PK Indentity

---------------------------------------------------------------------

ID int No Yes Yes

Descr varchar(30) No No No

FKID int Yes No No







I set my BO to map to this table, set ID and Descr to Do Not Allow NULL; FKID to Use nullable generic in BO mapper allow null option. When I save new record, I found that FKID is always ZERO instead of NULL if I leave FKID blank (bound in combobox). I figured out that myBO.AllowNullValuesOnNewRow = false.



So, I try to set myBO.AllowNullValuesOnNewRow = true but then I will hit error complaint that system unable to convert DBNull to string for textbox. I was thinking to change "Descr" to use "Return alternate on null" option.



May I know is it the prefered way? Or, any recommendation?



Thank you
By Trent L. Taylor - 1/30/2007

Strings do not support a nullable generic.  You will have to use the "Return Alternate Value" option for a string.  Generally when this is selected for a string, then you want to set the return value as "". 
By Alexnaldo C Santos - 1/31/2007

Hi,

I think that is better change the code generate to, like it :

public string MyField
{
  get {

            return CurrentRow.GetString("myField");
        }

    set

         { CurrentRow["myField"] = value; }

}

The "CurrentRow" class must have GetXXXXX for each type, like GetInt(..), GetDate(...), so you can return values more easy, like "null".

Regards,
Alexnaldo Santos

By StrataFrame Team - 2/1/2007

The CurrentRow property is a DataRow object reference, not a wrapper for a DataRow, and the DataRow class does not have GetXXX methods like the DbDataReader class does.  Generating the code in the properties was the most efficient solution.