Modifying an existing feature

Editing existing features is performed using essentially the same technique of editing the row and then calling FeatureDataTable.SaveInFeatureLayer(), FeatureLayer.SaveEdits() or if you are using a FeatureDataReader you can call the Update method. When updating an existing feature, you often have a selection representing the feature you wish to update. The selection is obtained by defining a QueryFilter, which may contain both a spatial and attribute query component, then passing this as a parameter to the FeatureLayer.GetDataTable Method to obtain a FeatureDataTable for the selection or call FeatureLayer.GetDataReader() to get back a DataReader. The Selection MapAction can assist you by providing graphic selection and returning a collection of FeatureDataTables. Using ADO calls, you can then update the appropriate rows or access the geometry you wish to update.

The following example shows how to change a value of selected features:

// Selects a specific cache layer 
FeatureLayer featureLayer = mobileCache1.Layers["parcels"] as FeatureLayer; 
// Checks if attributes are editable 
if (!featureLayer.AllowModify) 
  return; 
//
Query filter specifing feature IDs 
QueryFilter queryFilter = new QueryFilter(new int[] { 5473, 14004, 13997, 7404, 8556, 10490, 16117 });
// Sets the initial parcel number 
int apn = 100000000; 
//
Gets the position of the column to be edited 
int apnFieldIndex = featureLayer.Columns.IndexOf("APN"); 
// Using a feature datareader to update features 
using (FeatureDataReader featureDataReader = featureLayer.GetDataReader(queryFilter, null)) 
  {
  while(featureDataReader.Read()) 
    { 
    // Gets the feature ID 
    int fid = featureDataReader.GetFid(); 
    // Sets the parcel number
    featureDataReader.SetString(apnFieldIndex, apn.ToString()); 
    //Increments the parcel number 
    apn += 1; 
    // Prints info
    System.Diagnostics.Debug.WriteLine("FID: " + fid + ", APN: " + featureDataReader.GetValue(apnFieldIndex));
    // Updates the feature
    layer data table featureDataReader.Update(); 
    }
  }

9/20/2011