Storing NULL-value into row with not-null constraint

1355
4
11-18-2016 01:43 AM
CarstenSchumann
Occasional Contributor

Today I´ve encountered a really bad issue when stroing features to my geodatabase (I´m using a FileGDB, but colluegues of mine said it also occurs on SDE or MDB).

I created a new feature and set one of its values to NULL using

IFeature.set_Value(theFieldIndex, null)

. As the field has a not-null-constraint on it (checked it in ArcCatalog) I see its value is somehow converted to an empty string which I find really annoying. I´d expected to get an error when storing the feature as it violates the constraint. Swallowing the error and set it to an empty string is absolutely inacceptable as the empty string may be a valid value as well. However we can´t distinguish valid empty strings with invalid ones any more.

Is this intended behaviour? If so can I bypass it?

4 Replies
TedKowal
Occasional Contributor III

Test the field before you set its value?  

if (String.IsNullOrEmpty(myString))
{
   //do something
}‍‍‍‍

x ==null   --   x==string.Empty  Tests if you need to determine one or the other?

Why would you set a field to null when you have an non-null constraint within the database (sounds like a recipe for problems )  Handle nulls and emptyness before doing any database transactions.

0 Kudos
CarstenSchumann
Occasional Contributor

The question is not why I want to put null into a column with a non-null constraint, but why ArcGIS doesn´t complain when I try this. Imagine we have some client where we can enter values for new features. How should a user determine if he may or may not enter NULL into a given field? I´d expect an exception from ArcGIS in this case.

The whole point of the constraint seems quite useless to me if ArcGIS automatically circumvents the problem by resetting the value and thus avoid the error in the first place. We could get rid of those constraints then.

0 Kudos
MuratKarahan
New Contributor III

Hi Carsten,

Did you try ?

IFeature.set_Value(theFieldIndex, DBNull.Value)

Additional information about editing data in ArcMap;  with AdvancedArcMapSettings.exe which is located at "C:\Program Files (x86)\ArcGIS\Desktop10.X\Utilities" you can change the behaviour of storing empty strings as null.

AdvancedArcMapSettings.exe Storing empty strings as Null values

0 Kudos
CarstenSchumann
Occasional Contributor

Checking every value myself is quite overkill to me, as we have thousand of types with millions of attributes which I can´t check for `DBNull`. However as far as I understand the constraint should prevent exactly this, namely putting nulls into fields where it isn´t allowed. So why should I care myself?

Anyway the hint with the advanced settings might help, but as we are creating our own desktop-client I´m not sure we even have this program. I will check this.

0 Kudos