A <Null> Coded Value?

626
5
08-17-2011 06:44 AM
GregRieck
Regular Contributor
Hello,

I'm looking for some help in setting a value to <Null>. I have a field in a table of type Long and it is a coded value domain. In ArcMap I am able to assign a value of <Null> to the field and save it without error. I'd like to be able to do this programmatically.

How do I assign a <Null> to a Long data type in code?

  row.set_Value(FIELD INDEX, WHAT GOES HERE?);
  cur.UpdateRow(row);
G
0 Kudos
5 Replies
JamesCrandall
MVP Frequent Contributor
Just a quick shot, but have you tried Nullable(Of Integer)?  The problem is that in VB, Integers cannot be null (at least that's what I believe).  Setting your Integer variable to "Nothing" would only produce the default value of 0(zero).  But the Integer? Type should get you the result you want.

Try something like this:


  Dim myIntValue As Integer? = Nothing
  row.set_Value(FIELD INDEX, myIntValue);
  cur.UpdateRow(row);
G



Hello,

I'm looking for some help in setting a value to <Null>. I have a field in a table of type Long and it is a coded value domain. In ArcMap I am able to assign a value of <Null> to the field and save it without error. I'd like to be able to do this programmatically.

How do I assign a <Null> to a Long data type in code?


  row.set_Value(FIELD INDEX, WHAT GOES HERE?);
  cur.UpdateRow(row);
G
0 Kudos
GregRieck
Regular Contributor
Hi James,

Thanks for the response. Yes, I have tried all sorts of Nullable type implementations and they have not worked. I find it odd that a Coded Value Domain always presents with a "<Null>" option and allows you to assign it. Also, I do not have any defined coded value of "Null" and it still allows me to update the field to Null in ArcMap. So, I'm assuming there has to be a way to accomplish this in code, correct?

Some Examples...
Int? num = null;

Long? num = null;

Bool? b =null;
Object obj = b;
0 Kudos
GregRieck
Regular Contributor
I figured this out!

Turns out it had nothing to do with NULL. The problem was that the cursor was initialized as a SEARCH cursor but being used as an UPDATE cursor.

WRONG:

ICursor cur = Tab.Search(queryfilter, false);
row.set_Value(FIELD INDEX, WHAT GOES HERE?);  
cur.UpdateRow(row);
CORRECT:

ICursor cur = Tab.Update(queryfilter, false);
row.set_Value(FIELD INDEX, DBNull.Value);  
cur.UpdateRow(row);
0 Kudos
MichaelHoward1
New Contributor
Does anyone know how to accomplish this in Java?

I have tried null, "Null", etc. It seems that Java does not have a System.DBNull.Value like C# does.

How can I set the value of a field to null in my code?
0 Kudos
DubravkoAntonic
New Contributor III
I'm not Java but google is 🙂
http://bleu.west.spy.net/~dustin/spyjar/doc/2/net/spy/db/DBNull.html

does it help?
0 Kudos