Select to view content in your preferred language

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

1862
4
Jump to solution
12-12-2018 11:12 AM
KylePerri
Esri Contributor

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.

0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable

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

0 Kudos
4 Replies
RichRuh
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

0 Kudos
KylePerri
Esri Contributor

Hey Rich,

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

- Kyle

0 Kudos
by Anonymous User
Not applicable

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.

0 Kudos
KylePerri
Esri Contributor

Hey Sean,

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

0 Kudos