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 by the filter parameter. 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 instances of Feature subclasses (such as network features), 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 committed 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 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.
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 | IFeature Interface | IFeatureCursor Interface