Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.


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?

share|improve this question
    
Why did you just not send null? –  Ragi Yaser Burhum Jun 2 '11 at 17:40
    
A limitation in set_value, see: gis.stackexchange.com/questions/6381/… –  Roy Dallal Jun 2 '11 at 20:20
    
Have you tried putting a null value into your SQL Server DB manually? Does it work? –  Nathanus Jun 2 '11 at 20:48
    
Can you set the date field to null using the field calculator in arcmap? –  Kirk Kuykendall Jun 2 '11 at 23:07
    
From ArcMap trying to enter both ' '(space) and <Null> failed. –  Roy Dallal Jun 5 '11 at 12:28
show 1 more comment

1 Answer 1

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.