[GIS] How to insert DateTime null using IRowBuffer

arcobjectsenterprise-geodatabasesql server

I am using IRowBuffer/IFeatureBuffer to insert fields to SQL Server 2008 DB.
When inserting a field I am using:

public void SetValue(IRowBuffer buffer, string field, object value)
{
   int fieldIndex = buffer.Fields.FindField(field);
   buffer.set_Value(fieldIndex, value ?? DBNull.Value);
}

(meaning when inserting null value I am using DBNull.Value)

Using this code with integer/float fields with null value works without a problem.
But using this with DateTime result in the value:
01/01/0001 00:00:00
in the DB.

Edit: a bit more clarification
When using:

buffer.set_Value(10, DBNull.Value);

When 10 is the index for a nullable int field the DB has a value of null.
But when 10 is the index for a nullable datetime field the DB has a value of 01/01/0001 00:00:00 .
It's not a problem in .Net or using nullable types but rather a problem with ArcOjects.
I have already seen Null values in plugin data source

Do someone have a solution for this?
Am I doing something wrong?

Best Answer

Check IField.IsNullable before attempting to set a null value.

If you expected the field to be nullable, but IsNullable is false, then the field was defined incorrectly. If you are creating the field programmatically, then set IFieldEdit2.IsNullable to true. If you add it through the ArcMap UI, then make sure the Allow NULL values flag is set to Yes.