4

I have a script in VB.Net for grabbing values from one feature and assigning them to another. It works fine on shapefiles, but upon importing the same shapefiles into a file geodatabase, I get an error thrown at me.

Try
 'Start edit operation
 pEditor.StartOperation()
 'Update the new fields with the correct values
 pFeature.Value(pFeature.Fields.FindField("ReachCode")) = strReach
 pFeature.Value(pFeature.Fields.FindField("Measure")) = dblMeas
 pFCursor.UpdateFeature(pFeature)
 'End edit operation
 pEditor.StopOperation("UpdateFields")
 pFeature = pFCursor.NextFeature
Catch e As Exception
 'Cancel edits and exit loop
 pEditor.AbortOperation()
 MsgBox("There has been an error... edits will not be saved.", MsgBoxStyle.Exclamation, "Error")
 pEditor.StopEditing(False)
 Exit Sub
End Try

The loop is an update cursor for the feature class. When working in the geodatabase, the first update is applied fine, but when it reaches the "pFCursor.UpdateFeature(pFeature)" in the second loop, it throws this error:

"The cursor has been invalidated because the edit operation has stopped"

Is there some syntax change when working in geodatabases with respect to starting and stopping editing operations?

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked May 11, 2011 at 16:42
2
  • did you tried to use a regular cursor and feature.Store() ? Commented May 11, 2011 at 17:45
  • Using a COM releaser, search cursor, and feature.store did the trick, thanks George. Commented May 11, 2011 at 19:06

2 Answers 2

4

Solved, as per George's comment...

Using ComReleaser As ComReleaser = New ComReleaser
 Dim pFCursor As IFeatureCursor = pFClass.Search(Nothing, False)
 ComReleaser.ManageLifetime(pFCursor)
 Dim pFeature As IFeature = pFCursor.NextFeature
 Do Until pFeature Is Nothing
 ...
 Try
 'Start edit operation
 pEditor.StartOperation()
 'Update the new fields with the correct values
 pFeature.Value(pFeature.Fields.FindField("ReachCode")) = strReach
 pFeature.Value(pFeature.Fields.FindField("Measure")) = dblMeas
 pFeature.Store()
 'End edit operation
 pEditor.StopOperation("UpdateFields")
 pFeature = pFCursor.NextFeature
 Catch e As Exception
 'Cancel edits and exit loop
 pEditor.AbortOperation()
 MsgBox("There has been an error... edits will not be saved.", MsgBoxStyle.Exclamation, "Error")
 pEditor.StopEditing(False)
 Exit Sub
 End Try
 Loop
answered May 12, 2011 at 12:53
3

Did you tried to use IFeature.Store instead of ICursor.Update?

answered May 12, 2011 at 14:35

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.