Date Attribute Field Update

3991
13
03-21-2011 03:07 PM
JingjingLi
New Contributor II
I am facing an issue of updating Date field using null value. The Date field on the feature class is nullable. I created a feature service and loaded it in a silverlight app. I want to make a value in the field to be blank (null). But the attributes property of a graphic is IDictioanry<string, object> which is not nullable. How can I make it accept a null value?
Just like Graphic.Attributes["DateField"] = null
0 Kudos
13 Replies
JenniferNery
Esri Regular Contributor

gAttributes["UPDATEDATE"] = null 

Is g null? or is Attributes null? Check also that g.Attributes.ContainsKey("UPDATEDATE") maybe this returns null because field name does not match or FeatureLayer.OutFields does not include this field.
0 Kudos
JingjingLi
New Contributor II
You are right, by default DateField has a default length of 36.

You can try the following feature service that has a nullable DateField. Setting the attribute value to null does not raise any exception. You can wire up to EndSaveEdits and SaveEditsFailed to see that this new value is actually saved.

FeatureLayer layer = new FeatureLayer() { Url = "http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/HomelandSecurity/operations/FeatureServer/0", OutFields = new ESRI.ArcGIS.Client.Tasks.OutFields() { "*" } };
layer.Initialized += (s,e) =>
{
 layer.Update();
};
layer.UpdateCompleted += (s,e) =>
{
 var graphic = layer.Graphics.FirstOrDefault(g => (int)g.Attributes["objectid"] == 105635);
 graphic.Attributes["collection_time"] = null;
};
layer.Initialize();


If you are still experiencing issues please explain your use case with details about the data and application workflow so we can reproduce it here. Thanks.


I tried the easiest way to populate the field but still get a NullReferenceException error.
ESRI.ArcGIS.Client.FeatureLayer fl = theMap.Layers["flyr_RoadClosureLocations"] as ESRI.ArcGIS.Client.FeatureLayer;
            foreach (ESRI.ArcGIS.Client.Graphic g in fl.Graphics)
            {
                if (g.Attributes["UPID"].ToString() == "CAB_035")
                {
                    MessageBox.Show(g.Attributes["UPDATEDATE"].ToString());
                    g.Attributes["UPDATEDATE"] = null;
                }
            }


I uploaded three screenshots to show the settings of the feature class, the layer and the feature service. In the Silverlight App, I tried both 2.1 and 2.2 API but get the same error.
Environment:
ArcSDE 10 Sp1
ArcGIS Server 10 Sp1
0 Kudos
JingjingLi
New Contributor II
Finally I found the reason. The application has a FeatureDataGrid binding to the FeatureLayer. I have to set both FeatureDataGrid.Map and FeatureDataGrid.GraphicsLayer to null before I can assign a null value to g.Attribute["UPDATEDATE"]. See code below,
theFeatureDataGrid.Map = null;
            theFeatureDataGrid.GraphicsLayer = null;
            ESRI.ArcGIS.Client.FeatureLayer fl = theMap.Layers["flyr_RoadClosureLocations"] as ESRI.ArcGIS.Client.FeatureLayer;
            foreach (ESRI.ArcGIS.Client.Graphic g in fl.Graphics)
            {
                if (g.Attributes["UPID"].ToString() == "CAB_035")
                {
                    g.Attributes["UPDATEDATE"] = null;
                }
            }
            theFeatureDataGrid.Map = theMap;
            theFeatureDataGrid.GraphicsLayer = fl;

And it works.
0 Kudos
JenniferNery
Esri Regular Contributor
Thank you for reporting this. We'll try to get FeatureDataGrid fixed in the future release.
0 Kudos