How do I declare a TField as nullable?

1.3k Views Asked by At

I'm setting up an ADO-based client dataset, and when I try to insert a null value into a TIntegerField, on Post I get Project raised exception class EDatabaseError with message 'Non-nullable column cannot be updated to Null'.

I know I've seen a way to set a TField as nullable before, but I can't remember where or how. Does anyone know how to fix this?

EDIT: The field is set to Required = false at design time, and I've verified that it's still false at runtime, but I still get the error.

4

There are 4 best solutions below

1
On BEST ANSWER

Have you verified if the db field which this field represents have a not null constraint?

0
On

i don't know if this will help but it sounds familiar. check the properties on the fields of the ado dataset that feeds the cds. i know in d7 the cds internally takes on the readonly property of the provider's dataset regardless of its own readonly setting. the same problem may apply to the required property.

0
On
MyField.Required := False;
1
On

From help to Delphi 5:

property Required: Boolean;

but be aware of:

property CustomConstraint: String;

Also some implementation of classes inherited from TDataSet may add some logic on their own...