Setting default DateTime value = null

Posts   
 
    
jonas
User
Posts: 16
Joined: 04-Oct-2005
# Posted on: 01-Dec-2005 12:43:47   

I use databinding with llblgen and janus controls.

I want to bind a datetime property to a calendarcombo that allows null. If I have a record in the database and the datetime filed is null, I have found a way that works. I check OrginalValueForNull.

But, when I create a new entity it doesnt work. I have tried to SetNewValue(field, null) in the InitClassEmpty, but when I bind the control, the value is not null. I have checked both originalvalue and currentvalue and no one of them are null. The funny thing is in InitClassEmpty, when I set the value to null, TestCurrentFieldValueForNull changed from true to false....

So, now I always get the DateTime.MinValue when creating a new entity. And the database does not like that, neither does the user that sees the strange date on the screen

/Jonas

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 01-Dec-2005 14:37:22   

First the TestCurrentFieldValueForNull should be fixed in the latest release, please download and use the latest release.

Then for the null value, I suggest the following: 1- send the Datetime.MinValue from the UI code to your save function 2- In your Save function, check for DateTime.MinValue, and use Entity.SetNewFieldValue((int)EntityFieldIndex.FieldName, null); before saving the entity.

jonas
User
Posts: 16
Joined: 04-Oct-2005
# Posted on: 02-Dec-2005 10:01:35   

I installed the new version and the bug was corrected. But I still can´t get it to work properly.

Is it by design that I get the following results:

//Set value to null SetNewFieldValue((int)MachineFieldIndex.SalesDate, null);

TestCurrentFieldValueForNull(MachineFieldIndex.SalesDate)); //returns true TestOriginalFieldValueForNull(MachineFieldIndex.SalesDate)); //returns false this.Fields["SalesDate"].IsNull); //returns false

Why does the last row return false?? The IsNullable property is set to true.

/Jonas

jonas
User
Posts: 16
Joined: 04-Oct-2005
# Posted on: 02-Dec-2005 10:27:29   

I have run some more tests now, and I can not understand reallt how the logic works. I get the following results for a new entity, that has not been saved yet:

//The following is copied from the watch window in InitClassEmpty (watching this.Fields["SalesDate"]) CurrentValue {1/1/1} DataType {"System.DateTime"} DbValue <undefined value> IsNull false IsNullable true Name "SalesDate" OriginalValue <undefined value>

//I perform a few null tests. TestCurrentFieldValueForNull: True //Not accordning to the watch window TestOriginalFieldValueForNull: False //Not accordning to the watch window this.Fields["SalesDate"].IsNull: False //Correct, or...????

//I set the field value to null SetNewFieldValue((int)MachineFieldIndex.SalesDate, null);

//The watch window now returns the following results CurrentValue <undefined value> DataType {"System.DateTime"} DbValue <undefined value> IsNull false IsNullable true Name "SalesDate" OriginalValue {1/1/1}

TestCurrentFieldValueForNull: True //Correct TestOriginalFieldValueForNull: False //Correct this.Fields["SalesDate"].IsNull: False //Not correct, or...????

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 02-Dec-2005 16:01:54   

The following were copied from the LLBLGen Pro Reference Manual:

TestCurrentFieldValueForNull Returns true if the current value for the field with the fieldIndex passed in represents null/not defined, false otherwise. Should not be used for testing if the original value (read from the db) is NULL

TestOriginalFieldValueForNull Returns true if the original value for the field with the fieldIndex passed in, read from the persistent storage was NULL, false otherwise. Should not be used for testing if the current value is NULL, use TestCurrentFieldValueForNull for that.

EntityField.IsNull If the original value in the column for this entityfield is DBNull (NULL), this parameter should be set to true, otherwise to false. In BL Logic, it's impractical to work with NULL values, so these are converted to workable values. The developer can still determine if the original value was DBNull by checking this field. Using NULL values is not recommended

So as you see IsNull returns the same value of TestOriginalFieldValueForNull

jonas
User
Posts: 16
Joined: 04-Oct-2005
# Posted on: 02-Dec-2005 19:55:08   

Ok, but if you look at the data in my last post, I can´t see how the text in the reference manual explains my question:

"TestCurrentFieldValueForNull: Returns true if the current value for the field with the fieldIndex passed in represents null/not defined, false otherwise"

With CurrentValue = {1/1/1} TestCurrentFieldValueForNull returns true!

With OriginalValue = <undefined value> and DbValue = <undefined value> TestOriginalFieldValueForNull returns false, as well as IsNull does.

I find that strange.

/Jonas