ArcGIS Pro 3.8 API Reference Guide
ArcGIS.Core.Data Namespace / Row Class / Store Method
Example

In This Topic
    Store Method (Row)
    In This Topic
    Stores the row. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    public void Store()
    Public Sub Store() 
    Exceptions
    ExceptionDescription
    This table/feature does not support this operation. For example, it is from a joined table.
    A geodatabase-related exception has occurred.
    Remarks
    Should be called after modifications to the values are made. After calling Store() on feature service geodatabases, the row will not reflect edits that are made by calculation rules or changes to the ValidationStatus field. To see these changes, the row must be re-fetched.
    Example
    Modify a record within Row Events - using Row.Store
    // Attach an event handler to receive notifications when a row in the selected
    // table is changed. The subscription targets the first <see cref="ArcGIS.Desktop.Mapping.FeatureLayer"/> found in
    // the active map. Use this method to monitor and respond to edits made to table records within the current map
    // context.
    Table thisTable = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().FirstOrDefault().GetTable();
    RowChangedEvent.Subscribe(rowChangedEventArgs =>
      {
        // set the current row changed guid when you execute the Row.Store method
        // used for re-entry checking
        Guid _currentRowChangedGuid = new();
        // RowEvent callbacks are always called on the QueuedTask so there is no need
        // to wrap your code within a QueuedTask.Run lambda.
    
        var row = rowChangedEventArgs.Row;
    
        // check for re-entry  (only if row.Store is called)
        if (_currentRowChangedGuid == rowChangedEventArgs.Guid)
        {
          return;
        }
    
        var fldIdx = row.FindField("POLICE_DISTRICT");
        if (fldIdx != -1)
        {
          //Validate any change to �police district�
          //   cancel the edit if validation on the field fails
          if (row.HasValueChanged(fldIdx))
          {
            // cancel edit with invalid district (5)
            var value = row["POLICE_DISTRICT"].ToString();
            if (value == "5")
            {
              //Cancel edits with invalid �police district� values
              rowChangedEventArgs.CancelEdit($"Police district {row["POLICE_DISTRICT"]} is invalid");
            }
          }
          // update the description field
          row["Description"] = "Row Changed";
          //  this update with cause another OnRowChanged event to occur
          //  keep track of the row guid to avoid recursion
          _currentRowChangedGuid = rowChangedEventArgs.Guid;
          row.Store();
          _currentRowChangedGuid = Guid.Empty;
        }
      }, thisTable);
    Illustrate version conflict information from a reconcile operation
    {
      Task GetVersionConflictsInfoInUpdateDeleteTypeAsync(
        ServiceConnectionProperties featureServiceConnectionProperties,
        string featureClassName) => QueuedTask.Run(() =>
      {
        // To illustrate the conflict between versions,
        // the feature is updated in the child version and deleted in the parent version.
    
        long featureObjectIDForEdit = Int64.MinValue;
    
        // Get branch versioned service
        using (Geodatabase fsGeodatabase = new Geodatabase(featureServiceConnectionProperties))
        using (VersionManager versionManager = fsGeodatabase.GetVersionManager())
        using (Version defaultVersion = versionManager.GetDefaultVersion())
        using (Geodatabase defaultGeodatabase = defaultVersion.Connect())
        using (FeatureClass defaultFeatureClass = defaultGeodatabase.OpenDataset<FeatureClass>(featureClassName))
        using (FeatureClassDefinition defaultFeatureClassDefinition = defaultFeatureClass.GetDefinition())
        {
          // Create a feature in the default version to edit in a branch
          defaultGeodatabase.ApplyEdits(() =>
          {
            using (RowBuffer rowBuffer = defaultFeatureClass.CreateRowBuffer())
            {
              rowBuffer["NAME"] = "Loblolly Pine";
              rowBuffer["TREEAGE"] = 1;
              rowBuffer[defaultFeatureClassDefinition.GetShapeField()] = new MapPointBuilderEx(new Coordinate2D(1, 1),
                SpatialReferenceBuilder.CreateSpatialReference(4152, 0)).ToGeometry();
    
              using (Feature feature = defaultFeatureClass.CreateRow(rowBuffer))
              {
                featureObjectIDForEdit = feature.GetObjectID();
              }
            }
          });
          // Add newly created feature in the filter
          QueryFilter queryFilter = new QueryFilter { ObjectIDs = new List<long> { featureObjectIDForEdit } };
    
          // Create a branch version
          VersionDescription versionDescription = new VersionDescription("UpdateDeleteConflictType",
            "Update-Delete version conflict type", VersionAccessType.Public);
    
          // Edit the feature in the branch
          using (Version editVersion = versionManager.CreateVersion(versionDescription))
          using (Geodatabase branchGeodatabase = editVersion.Connect())
          using (FeatureClass featureClass = branchGeodatabase.OpenDataset<FeatureClass>(featureClassName))
          using (RowCursor rowCursor = featureClass.Search(queryFilter, false))
          {
            branchGeodatabase.ApplyEdits(() =>
            {
              while (rowCursor.MoveNext())
              {
                using (Row row = rowCursor.Current)
                {
                  row["TREEAGE"] = 100;
                  row["NAME"] = $"{row["Name"]}_EditInBranch";
                  row.Store();
                }
              }
            });
    
            // Delete the feature from the default version
            defaultGeodatabase.ApplyEdits(() =>
            {
              defaultFeatureClass.DeleteRows(queryFilter);
            });
    
            // Reconcile options
            ReconcileOptions reconcileOptions = new ReconcileOptions(defaultVersion)
            {
              ConflictResolutionType = ConflictResolutionType.FavorEditVersion,
              ConflictDetectionType = ConflictDetectionType.ByRow,
              ConflictResolutionMethod = ConflictResolutionMethod.Continue
            };
    
            // Reconcile with default
            ReconcileResult reconcileResult = editVersion.Reconcile(reconcileOptions);
    
            // Check for conflicts
            bool hasConflictsReconcileResults = reconcileResult.HasConflicts;
            bool hasConflictsAfterReconcile = editVersion.HasConflicts();
    
            // Fetch conflicts
            IReadOnlyList<Conflict> conflictsAfterReconcile = editVersion.GetConflicts();
    
            // Iterate conflicts
            foreach (Conflict conflict in conflictsAfterReconcile)
            {
              // Object ID of row where conflict occurs
              long objectId = conflict.ObjectID;
    
              ConflictType conflictType = conflict.ConflictType;
    
              IReadOnlyList<FieldValue> ancestorVersionValues = conflict.AncestorVersionValues;
              object nameAncestor = ancestorVersionValues.FirstOrDefault(f => f.FieldName.Contains("NAME")).Value;
              object treeAgeAncestor =
                ancestorVersionValues.FirstOrDefault(f => f.FieldName.Contains("TREEAGE")).Value;
    
              IReadOnlyList<FieldValue> childVersionValues = conflict.ChildVersionValues;
              object nameChild = childVersionValues.FirstOrDefault(f => f.FieldName.Contains("NAME")).Value;
              object treeAgeChild = childVersionValues.FirstOrDefault(f => f.FieldName.Contains("TREEAGE")).Value;
    
              IReadOnlyList<FieldValue> parentVersionValues = conflict.ParentVersionValues;
    
              IReadOnlyList<Field> originalFields = defaultFeatureClassDefinition.GetFields();
    
              string datasetName = conflict.DatasetName;
            }
          }
        }
      });
    }
    Modifying a Row
    {
      await QueuedTask.Run(() =>
      {
        string message = String.Empty;
        bool modificationResult = false;
        using (Geodatabase geodatabase = new Geodatabase(new DatabaseConnectionFile(new Uri("path\\to\\sde\\file\\sdefile.sde"))))
        using (Table enterpriseTable = geodatabase.OpenDataset<Table>("LocalGovernment.GDB.piCIPCost"))
        {
          EditOperation editOperation = new EditOperation();
          editOperation.Callback(context =>
          {
            QueryFilter openCutFilter = new QueryFilter { WhereClause = "ACTION = 'Open Cut'" };
    
            using (RowCursor rowCursor = enterpriseTable.Search(openCutFilter, false))
            {
              TableDefinition tableDefinition = enterpriseTable.GetDefinition();
              int subtypeFieldIndex = tableDefinition.FindField(tableDefinition.GetSubtypeField());
    
              while (rowCursor.MoveNext())
              {
                using (Row row = rowCursor.Current)
                {
                  // In order to update the Map and/or the attribute table.
                  // Has to be called before any changes are made to the row.
                  context.Invalidate(row);
    
                  row["ASSETNA"] = "wMainOpenCut";
    
                  if (Convert.ToDouble(row["COST"]) > 700)
                  {
                    // Abandon asset if cost is higher than 700 (if that is what you want to do).
                    row["ACTION"] = "Open Cut Abandon";
                    row[subtypeFieldIndex] = 3; //subtype value for "Abandon"
                  }
    
                  //After all the changes are done, persist it.
                  row.Store();
    
                  // Has to be called after the store too.
                  context.Invalidate(row);
                }
              }
            }
          }, enterpriseTable);
    
          try
          {
            modificationResult = editOperation.Execute();
            if (!modificationResult)
            {
              message = editOperation.ErrorMessage;
            }
          }
          catch (GeodatabaseException exObj)
          {
            message = exObj.Message;
          }
        }
    
        if (!string.IsNullOrEmpty(message))
        {
          Debug.WriteLine(message);
        }
      });
    }
    Modifying a Feature
    {
      await QueuedTask.Run(() =>
      {
        string message = String.Empty;
        bool modificationResult = false;
    
        using (Geodatabase geodatabase = new Geodatabase(new DatabaseConnectionFile(new Uri("path\\to\\sde\\file\\sdefile.sde"))))
        using (FeatureClass enterpriseFeatureClass = geodatabase.OpenDataset<FeatureClass>("LocalGovernment.GDB.FacilitySite"))
        {
          FeatureClassDefinition facilitySiteDefinition = enterpriseFeatureClass.GetDefinition();
    
          int ownTypeIndex = facilitySiteDefinition.FindField("OWNTYPE");
          int areaIndex = facilitySiteDefinition.FindField(facilitySiteDefinition.GetAreaField());
    
          EditOperation editOperation = new EditOperation();
          editOperation.Callback(context =>
          {
            QueryFilter queryFilter = new QueryFilter
            {
              WhereClause = "FCODE = 'Hazardous Materials Facility' AND OWNTYPE = ' '"
            };
    
            using (RowCursor rowCursor = enterpriseFeatureClass.Search(queryFilter, false))
            {
              while (rowCursor.MoveNext())
              {
                using (Feature feature = (Feature)rowCursor.Current)
                {
                  // In order to update the Map and/or the attribute table.
                  // Has to be called before any changes are made to the row
                  context.Invalidate(feature);
    
                  // Transfer all Hazardous Material Facilities to the City.
                  feature[ownTypeIndex] = "Municipal";
    
                  if (Convert.ToDouble(feature[areaIndex]) > 50000)
                  {
                    // Set the Shape of the feature to whatever you need.
                    List<Coordinate2D> newCoordinates = new List<Coordinate2D>
                    {
                        new Coordinate2D(1021570, 1880583),
                        new Coordinate2D(1028730, 1880994),
                        new Coordinate2D(1029718, 1875644),
                        new Coordinate2D(1021405, 1875397)
                    };
    
                    feature.SetShape(new PolygonBuilderEx(newCoordinates).ToGeometry());
                  }
    
                  feature.Store();
    
                  // Has to be called after the store too
                  context.Invalidate(feature);
                }
              }
            }
          }, enterpriseFeatureClass);
    
          try
          {
            modificationResult = editOperation.Execute();
            if (!modificationResult)
            {
              message = editOperation.ErrorMessage;
            }
          }
          catch (GeodatabaseException exObj)
          {
            message = exObj.Message;
          }
        }
    
        if (!string.IsNullOrEmpty(message))
        {
          Debug.WriteLine(message);
        }
      });
    }
    Creating a new Annotation Feature in an Annotation FeatureClass using a RowBuffer
    {
      Task CreatingAnAnnotationFeatureAsync(Geodatabase geodatabase) => QueuedTask.Run(() =>
      {
        using (AnnotationFeatureClass annotationFeatureClass = geodatabase.OpenDataset<AnnotationFeatureClass>("Annotation // feature // class // name"))
        using (AnnotationFeatureClassDefinition annotationFeatureClassDefinition = annotationFeatureClass.GetDefinition())
        using (RowBuffer rowBuffer = annotationFeatureClass.CreateRowBuffer())
        using (AnnotationFeature annotationFeature = annotationFeatureClass.CreateRow(rowBuffer))
        {
          annotationFeature.SetAnnotationClassID(0);
          annotationFeature.SetStatus(AnnotationStatus.Placed);
    
          // Get the annotation labels from the label collection
          IReadOnlyList<CIMLabelClass> labelClasses =
            annotationFeatureClassDefinition.GetLabelClassCollection();
    
          // Setup the symbol reference with the symbol id and the text symbol
          CIMSymbolReference cimSymbolReference = new CIMSymbolReference();
          cimSymbolReference.Symbol = labelClasses[0].TextSymbol.Symbol;
          cimSymbolReference.SymbolName = labelClasses[0].TextSymbol.SymbolName;
    
          // Setup the text graphic
          CIMTextGraphic cimTextGraphic = new CIMTextGraphic();
          cimTextGraphic.Text = "Charlotte, North Carolina";
          cimTextGraphic.Shape = new MapPointBuilderEx(new Coordinate2D(-80.843, 35.234), SpatialReferences.WGS84)
            .ToGeometry();
          cimTextGraphic.Symbol = cimSymbolReference;
    
          // Set the symbol reference on the graphic and store
          annotationFeature.SetGraphic(cimTextGraphic);
          annotationFeature.Store();
        }
      });
    }
    Requirements

    Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)

    ArcGIS Pro version: 3.0 or higher.
    See Also