Select to view content in your preferred language

Getting Attributes from a standalone table in FeatureService

963
4
07-28-2011 02:28 PM
YaoMo2
by
Emerging Contributor
Hi all,

I'm trying to create a featuredataform that allow users to edit attributes of a standalone table in a SDE geodatabase.

I initialized a FeatureLayer linking to the table in a FeatureService and tried to pass all the attributes to a FeatureDataForm.GraphicSource for editing.

I cannot retrieve the records using featurelayer.Graphics.Attributes["attr1"]. It seems that the FeatureLayer doesn't contain any graphics.

Is there any way to do pass the information to the FeatureDataForm?

Thanks!!!

Jerry
0 Kudos
4 Replies
JenniferNery
Esri Regular Contributor
Do you have a table similar to this: http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/SanFrancisco/311Incidents/FeatureServer/1

If you want to edit entries of this table, you can create a FeatureLayer with this Url. Set OutFields to include attributes you need to edit. You need to Initialize the FeatureLayer and also call Update after it has been initialized, this will perform the query on your table. Once update is completed, you can set FeatureDataForm.GraphicSource.

If you are editing a specific row with ID, you can do something like:
 var graphic = l.Graphics.FirstOrDefault(g => g.Attributes[l.LayerInfo.ObjectIdField] == (int) objId); 
 MyFeatureDataForm.FeatureLayer = l;    
 MyFeatureDataForm.GraphicSource = graphic;
0 Kudos
YaoMo2
by
Emerging Contributor
Yes, My Table is similar except that there's no relation.

I've initialized my feature layer in XAML:
<esri:FeatureLayer ID="TreeEdit_FeatureLayer"
                 Url="http://chgisservice/ArcGIS/rest/services/test/tree_inv_test2_FeatureAccess/FeatureServer/1"
                 DisableClientCaching="True"
                 Mode="OnDemand"
                 SelectionColor="Red"
                 FeatureSymbol="{StaticResource MyMarkerSymbol}"
                 OutFields="*"/>


Then I call update once a button is clicked (Functions similar to this post😞
        private void editbutton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                FeatureLayer f = Map.Layers["TreeEdit_FeatureLayer"] as FeatureLayer;
                MessageBox.Show("initialized: " + f.IsInitialized.ToString()); //will display True
                f.UpdateCompleted += new EventHandler(featurelayer_updatecompleted);
                f.UpdateFailed +=new EventHandler<TaskFailedEventArgs>(f_UpdateFailed);
                f.Update();
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message);
            }
        }

My Update Completed Function to test the number of graphics:
private void featurelayer_updatecompleted(object sender, System.EventArgs e)
        {
            FeatureLayer ff = Map.Layers["TreeEdit_FeatureLayer"] as FeatureLayer;
            MessageBox.Show("update completed.");
            MessageBox.Show("featurelayer graphics count: " + ff.Graphics.Count.ToString());
        }
void f_UpdateFailed(object sender, TaskFailedEventArgs e)
        {
            MessageBox.Show(e.Error.Message);
        }


It seems that the update will always go to UpdateFailed event. The MessageBox shows "Unable to Complete Operation".

I checked my table using regular querytask. It returns correct records as usual.

I still couldn't figure out where the problem is.

Thanks!!
0 Kudos
JenniferNery
Esri Regular Contributor
Since you are working with a table, this FeatureLayer should reside in code-behind and not part of your Map.
Something like this:
FeatureLayer l = new FeatureLayer()
{
 Url = "http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/SanFrancisco/311Incidents/FeatureServer/1",
 AutoSave = false
};   
l.OutFields.Add("*");
l.Initialized += (s, e) =>
{
 l.Update();
};
l.Initialize();
0 Kudos
YaoMo2
by
Emerging Contributor
I figured out that it's the Mode = "OnDemand" that messed up with the update event.

and yes, I should initialize the featurelayer in code behind.

Thanks so much for your help!
0 Kudos