Returns a cursor that can be used to update features selected by the specified query.
[Visual Basic 6.0] Function Update(
ByVal filter As IQueryFilter, _
ByVal Recycling As Boolean _
) As IFeatureCursor
[Visual Basic .NET] Public Function Update ( _ ByVal filter As IQueryFilter, _ ByVal Recycling As Boolean _ ) As IFeatureCursor
[C#] public IFeatureCursor Update ( IQueryFilter filter, bool Recycling );
[Java] public IFeatureCursor update ( IQueryFilter filter, Boolean Recycling ) throws IOException, AutomationException
[C++] HRESULT Update( IQueryFilter* filter, VARIANT_BOOL Recycling, IFeatureCursor** Cursor );
Parameters
filter [in]
filter is a parameter of type IQueryFilter
Recycling [in]
Recycling is a parameter of type VARIANT_BOOL
Cursor [out, retval]
Cursor is a parameter of type IFeatureCursor
Update opens an update cursor on the features specified by an attribute and/or spatial query as specified in an IQueryDef . If a number of features selected by a particular query are to be updated and each feature is to be updated to a separate value then the update cursor is faster than doing an individual feature level update for each feature. The update is performed on the current 'cursor position'.
Update cursors can be used on a custom object, with guaranteed polymorphic behavior. Update cursors can be used either inside or outside of an edit session. If used inside an edit session, the changes are not commited to the base table until the edit session is saved. Network feature classes, Topology feature classes, feature classes that participate in composite relationships or other relationships with messaging and some custom feature classes may only be updated within an edit session. If you attempt to use an update cursor on one of these classes outside of an edit session, it will fail. In addition, edits to features that participate in a Topology or Geometric Network must be bracketed within an edit operation.
If an the insert cursor is used on non-simple features (such as network features), the cursor will revert to using IFeature::Store.
If you are creating custom features that do not have polymorphic behavior on creation, update and deletion you can implement the IObjectClassInfo interface to set the CanBypassStoreMethod property to true. Doing this will cause the geodatabase to bypass the custom feature implementation for update and insert cursors used with that custom feature class. Also, you can implement the IObjectClassInfo2 interface on the object class extension and return true to CanBypassEditSession method to indicate the those custom features can be updated outside of an edit session.
The following example uses an update cursor to change the value of a particular field for a set of features in a feature class.
Dim pFeatcls As IFeatureClass
Dim pFeatLayer As IFeatureLayer
Dim pDoc As IMxDocument
Dim pMap As IMap
Set pDoc = ThisDocument
Set pMap = pDoc.Maps.Item(0)
Set pFeatLayer = pMap.Layer(0)
Set pFeatcls = pFeatLayer.FeatureClass
' +++ create the query filter
Dim pQueryFilter As IQueryFilter
Set pQueryFilter = New QueryFilter
With pQueryFilter
.WhereClause = "subtype = 'COM'"
.SubFields = "FID, Type"
End With
' +++ get the field we are interested in updating
Dim lFld As Long
Dim pFlds As IFields
Dim pTable As ITable
Dim pFeatCur As IFeatureCursor
Dim pFeat As IFeature
Set pFeatCur = pFeatcls.Update(pQueryFilter, False)
Set pFlds = pFeatcls.Fields
lFld = pFlds.FindField("Type")
' +++ loop through each feature and update
' +++ the field to its new value
Set pFeat = pFeatCur.NextFeature
While Not pFeat Is Nothing
Debug.Print "The old type: " & pFeat.Value(lFld)
pFeat.Value(lFld) = "ABC"
pFeatCur.UpdateFeature pFeat
Debug.Print "The new type: " & pFeat.Value(lFld)
Set pFeat = pFeatCur.NextFeature
Wend
IFeatureClass Interface | IEnumRow Interface | IFeatureCursor Interface | IFeature Interface