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.
Solved! Go to Solution.
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.
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
Hey Rich,
Thanks for the reply. Unfortunately, this didn't fix it for me.
- Kyle
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.
Hey Sean,
Thanks for the reply. This was in fact the issue. Once I removed the operation type it worked.