Edit Operation failing when trying to Modify rows in a feature class

106
4
Jump to solution
12-12-2018 11:12 AM
Highlighted
New Contributor III

I am trying to loop through every row in a feature class and edit one of it's fields, but for some reason it always fails.

Here is my code:

QueuedTask.Run(async () =>
            {
foreach(var featureClass in featureClasses)
                        {
                            var editOperation = new EditOperation()
                            {
                                Name = "Revert IsEdited Field",
                                EditOperationType = EditOperationType.Short,
                                ShowProgressor = false
                            };
                            var editedRowsQuery = new QueryFilter()
                            {
                                WhereClause = $"{IS_EDITED_FIELD} = 1"
                            };
                            try
                            {
                                using (var rowCursor = featureClass.Search(editedRowsQuery))
                                {
                                    int isEditedFieldIndex = rowCursor.FindField(IS_EDITED_FIELD);
                                    while (rowCursor.MoveNext())
                                    {
                                        using (var row = rowCursor.Current)
                                        {
                                            editOperation.Modify(row, isEditedFieldIndex, 0);
                                        }
                                    }
                                }
                            }
                            catch (System.ArgumentException)
                            {
                                continue;
                            }
                            catch (GeodatabaseException)
                            {
                                continue;
                            }
                            bool succeeded = await editOperation.ExecuteAsync();
                            featureClass.Dispose();
                        }‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Is there something I'm doing wrong?

I've tried using editOperation.Execute as well, but same error.

Reply
0 Kudos
1 Solution

Accepted Solutions
Highlighted
Esri Regular Contributor

Kyle,

You're explicitly setting the edit operation type to short, the operation will fail if the featureclass is "long" or registered as versioned. Normally there's no need to explicitly this, the operation works it out based on the edits.

Also check the editoperation.errormessage property after the failure to see if there's any known error being reported.

View solution in original post

Reply
0 Kudos
4 Replies
Highlighted
Esri Regular Contributor

Hi Kyle,

The first thing I would try is to change the call to FeatureClass.Search as follows:

using (var rowCursor = featureClass.Search(editedRowsQuery, false))

This creates a non-recycling cursor, which is what you want for editing.

Recycling cursors are described in more detail in the conceptual doc.

I hope this helps,

--Rich

Reply
0 Kudos
Highlighted
New Contributor III

Hey Rich,

Thanks for the reply. Unfortunately, this didn't fix it for me.

- Kyle

Reply
0 Kudos
Highlighted
Esri Regular Contributor

Kyle,

You're explicitly setting the edit operation type to short, the operation will fail if the featureclass is "long" or registered as versioned. Normally there's no need to explicitly this, the operation works it out based on the edits.

Also check the editoperation.errormessage property after the failure to see if there's any known error being reported.

View solution in original post

Reply
0 Kudos
Highlighted
New Contributor III

Hey Sean,

Thanks for the reply. This was in fact the issue. Once I removed the operation type it worked.

Reply
0 Kudos