AnsweredAssumed Answered

ArcObject Editor Addins error while using IDifferenceCursorEx in 10.5

Question asked by bluememory on Jul 31, 2018

Hi, I try to get the updated fields while user save edit in editor toolbox.  The error will only occur when I update exactly 200 / 400 / 600 ... records on sql server.

Here is the code

void OnBeforeStopEditing(bool save)
        {
            IWorkspaceEdit2 workspaceEdit2 = (IWorkspaceEdit2)ArcMap.Editor.EditWorkspace;
            try
            {
                if (!save)
                {
                    log(" > not save, return.");
                    return;
                }

                if (!(ArcMap.Editor.EditWorkspace is ISqlWorkspace))
                    return;
               
                IDifferenceCursorEx updateDifferenceCursorEx = null;
                IDataChangesEx dataChanges = workspaceEdit2.get_EditDataChanges(esriEditDataChangesType.esriEditDataChangesWithinSession);
                IEnumBSTR modifiedClasses = dataChanges.ModifiedClasses;

                // For simplify, only get the first updated class
                string modifiedClass = modifiedClasses.Next();
               
                // Prepare the output parameters.
                int featureID = -1;
                IRow sourceRow = null;
                IRow differenceRow = null;
                ILongArray fieldIndexes = null;

                // Iterate through the cursor.
                updateDifferenceCursorEx = dataChanges.ExtractEx(modifiedClass, esriDifferenceType.esriDifferenceTypeUpdateNoChange);
                updateDifferenceCursorEx.Next(out featureID, out sourceRow, out differenceRow, out fieldIndexes);
                while (featureID != -1)
                {
                    //Console.WriteLine("Changes for feature {0}:", featureID);
                    //// Go to each changed field and display the old and new values.
                    //for (int i = 0; i < fieldIndexes.Count; i++)
                    //{
                    //    Console.WriteLine("Previous value: {0}", sourceRow.get_Value(i));
                    //    Console.WriteLine("Current value: {0}", differenceRow.get_Value(i));
                    //}
                    updateDifferenceCursorEx.Next(out featureID, out sourceRow, out differenceRow,
                      out fieldIndexes);
                }
            }
            catch (Exception ex)
            {
                log(ex.ToString());
                ShowError("Unhandled error occurred\n" + ex.ToString());
            }
        }

Outcomes