Updating data in a Table

546
4
Jump to solution
05-28-2012 10:54 PM
JoeHershman
MVP Regular Contributor
I have followed the path outlined in the thread on editing records http://forums.arcgis.com/threads/21714-Editing-Tables-in-Feature-Service-with-Silverlight-4 and while that works for adding new records it does not address editing of existing rows in a table which I have found quite difficult partially because of what I would consider a bug with the API.

When I create a FeatureLayer object in code like shown in the thread on adding records and call initialize on the FeatureLayer, when the Initialized is returned the Graphics collection is empty even though there are objects in my table.  I have played around with different approaches when creating the FeatureLayer, giving OIDs putting a Where clause of ???OBJECTID >  0,??? but in all cases the Graphics collection is empty and never populates.  What I have also tried is to add the FeatureLayer to the map in code still no luck. 

However, when the FeatureLayer is added to the map in Xaml it does have a populated Graphics collection.  Why is there is different behavior when adding through Xaml compared to adding in code?  I would consider that a bug.
Once my Graphics collection is populated I am able to update a record by finding the proper Graphic object and changing the attributes and calling Save.  Something along the lines of;

    Graphic graphic = _featureLayer.Graphics.Where(g => (int)g.Attributes[OBJECTID] == ObjectId).FirstOrDefault();      graphic[NAME] = newValue;      _feaureLayer.Save();


Adding the FeatureLayer in Xaml is not really an option in how my application is designed (well it is an option, one that defeats the entire point in having architected a modular MVVM application).  To me something is wrong, you should not have to add a FeatureLayer in Xaml to make something work, creating the object in code and calling initialize should have the same behavior.  Could someone look into this, perhaps I am missing something.

Cheers
Thanks,
-Joe
0 Kudos
1 Solution

Accepted Solutions
JoeHershman
MVP Regular Contributor
So went back to this to see if I could track down the problem.  Set up everything the same as it had been, and it is working update fine Graphics are loaded.  I looked back in subversion and I swear it is the same code that was failing.  I am going to blame it on solar flares or something of that nature.  All I know is it is working so I will just be happy about that and move forward.

Thanks
-Joe
Thanks,
-Joe

View solution in original post

0 Kudos
4 Replies
DominiqueBroux
Esri Frequent Contributor
When I create a FeatureLayer object in code like shown in the thread on adding records and call initialize on the FeatureLayer, when the Initialized is returned the Graphics collection is empty even though there are objects in my table.


The graphics collection is populated after the initialization phase during the draw of the map. So it's normal that the graphics collection is empty when the Initialized event is fired.

You can subscribe to Updated event instead.

Also, did you insert your feature layer in a Map? If you didn't, you have to call 'Update' by yourself else the feature layer won't ever be updated.
0 Kudos
JoeHershman
MVP Regular Contributor
The graphics collection is populated after the initialization phase during the draw of the map. So it's normal that the graphics collection is empty when the Initialized event is fired.

You can subscribe to Updated event instead.

Also, did you insert your feature layer in a Map? If you didn't, you have to call 'Update' by yourself else the feature layer won't ever be updated.


If I call Initialize on the FeatureLayer and then try to call Update I get a null reference error, which is happening internal to the FeatureLayer object (my objects are not null).  I added the Update handlers and when the FeatureLayer is added to the map via code it fails on Update with a Error Code 400:  Unable to complete operation "Unable to perform query."  This occurs whenever I zoom the map.  Again this will work when the FeatureLayer is added in xaml

Cheers
-Joe
Thanks,
-Joe
0 Kudos
DominiqueBroux
Esri Frequent Contributor
I added the Update handlers and when the FeatureLayer is added to the map via code it fails on Update with a Error Code 400: Unable to complete operation "Unable to perform query." This occurs whenever I zoom the map. Again this will work when the FeatureLayer is added in xaml


I don't understand why  afeature layer added by code would react differently from a feature layer added by XAML.
Could you share a code snippet alowing to reproduce the issue?

Also perhaps using fiddler to look at the request sent to the request might give a clue.
0 Kudos
JoeHershman
MVP Regular Contributor
So went back to this to see if I could track down the problem.  Set up everything the same as it had been, and it is working update fine Graphics are loaded.  I looked back in subversion and I swear it is the same code that was failing.  I am going to blame it on solar flares or something of that nature.  All I know is it is working so I will just be happy about that and move forward.

Thanks
-Joe
Thanks,
-Joe
0 Kudos