Select to view content in your preferred language

IFeatureClass.Update

3163
15
03-06-2013 01:34 PM
GhassanKarwchan
Occasional Contributor
I am migrating .NET code from 9.3 to 10.1
The code is using
IFeatureClass.Update(queryfileter, true) where true is for recycling.


I know recycling should not be used when we do update, and actually it was permitted on 9.3 in spite of being undesirable, and it is totally prevented on 10.1

On 10.1 the code is not working, so I assumed it is because of the recycle, and I did change it to false.

And here my first question. If it is not permitted , then why you give it as an option in 10.1 when we open a cursor of update?

Is it possible to use it in 10.1 with recycle being true?


and my second question.
After I changed it to false, I was able to successfully update the features.
It worked for all kind of update.
But it is hanging on one place, where I am selecting more that 100,000 rows at once.

The IFeatureClass.Update is hanging, without doing anything.

I want to ask if any one has any idea on how to do what I am doing on 10.1

P.S, I am maintaining very bad written and messy code, and what I need is just to migrate it to 10.1 with the less modification possible.

Thanks
0 Kudos
15 Replies
AlexanderGray
Honored Contributor
Leo is making valid points and was right to ask what is the error message.  The other half of the equation is, of course, what code is generating this message.  However, if one assumes there is only one way to edit, one might not think to provide that information. With a little more info to start with there is a lot less confusion.
0 Kudos
soniadickerson1
Regular Contributor
This post has been very helpful.  I had the same error but not for the same reason.

I found two ways to successfully edit the attributes and would like to know which way is better.

This one uses Update:
   _SFRMPSelectionSet.Update(null, false, out pCursor);         
         if (pCursor == null) { return false; }
           pRow = pCursor.NextRow();
           while (pRow != null)
             {
                 foreach (var pair in dictFieldsValues)
                 {
                   fldIndex = _SFRMPFeatureLayer.FeatureClass.Fields.FindField(pair.Key);
                   objectValue = pair.Value;          
                   pRow.set_Value(fldIndex, objectValue);
                 }
              pCursor.UpdateRow(pRow);
              pRow = pCursor.NextRow();



This one uses Store:
 _SFRMPSelectionSet.Search(null, false, out pCursor);        
         if (pCursor == null) {return false; }
           pRow = pCursor.NextRow();
           while (pRow != null)
             {
                 foreach (var pair in dictFieldsValues)
                 {
                   fldIndex = _SFRMPFeatureLayer.FeatureClass.Fields.FindField(pair.Key);
                   objectValue = pair.Value;
                     pRow.set_Value(fldIndex, objectValue);
                 }
              pRow.Store();
              pRow = pCursor.NextRow();


Thank you so much.
0 Kudos
NeilClemmons
Honored Contributor
This post has been very helpful.  I had the same error but not for the same reason.

I found two ways to successfully edit the attributes and would like to know which way is better.

This one uses Update:
   _SFRMPSelectionSet.Update(null, false, out pCursor);         
         if (pCursor == null) { return false; }
           pRow = pCursor.NextRow();
           while (pRow != null)
             {
                 foreach (var pair in dictFieldsValues)
                 {
                   fldIndex = _SFRMPFeatureLayer.FeatureClass.Fields.FindField(pair.Key);
                   objectValue = pair.Value;          
                   pRow.set_Value(fldIndex, objectValue);
                 }
              pCursor.UpdateRow(pRow);
              pRow = pCursor.NextRow();



This one uses Store:
 _SFRMPSelectionSet.Search(null, false, out pCursor);        
         if (pCursor == null) {return false; }
           pRow = pCursor.NextRow();
           while (pRow != null)
             {
                 foreach (var pair in dictFieldsValues)
                 {
                   fldIndex = _SFRMPFeatureLayer.FeatureClass.Fields.FindField(pair.Key);
                   objectValue = pair.Value;
                     pRow.set_Value(fldIndex, objectValue);
                 }
              pRow.Store();
              pRow = pCursor.NextRow();


Thank you so much.


In general, using the Update cursor is faster, especially if you're updating a large number of records.  However, there is a certain amount of overhead that comes with using the Update cursor.  If you're only going to be updating a handful of records (less than a hundred or so), then the Store method is probably going to be quicker.  If you don't know how many records you're going to be updating or if you're writing a general function where the number can vary, then go with the Update cursor.
0 Kudos
soniadickerson1
Regular Contributor
Thanks.

If I set recycling to true, correct me if I'm mistaken, but each feature will be release as soon as it moves to the next row.

_SFRMPSelectionSet.Update(null, true, out pCursor);

Per my testing, setting the recycling value to true does not cause any errors on low record volume.

Wouldn't this be a good way to go?
0 Kudos
NeilClemmons
Honored Contributor
No, a recycling cursor does not release the feature objects.  It uses the same instance of a Feature object over and over.  For this reason, you shouldn't use a recycling cursor if you intend to modify the features it contains.
0 Kudos
LeoDonahue
Deactivated User
Hi Sonia,

Everyone should really have this topic under their belt.  "How to use cursors in the geodatabase"

I"m not sure "better way" is the phrase I would use. The options are based on what type of data you are editing and whether you are in an edit session.  You may want to call update, but if the features you are editing are complex, you get overruled.

When working with simple features and edit sessions in an Engine application, it's recommended that a search cursor be used to take advantage of batched updates in edit operations.  Outside of edit sessions, an update cursor allows performance and error handling advantages.  With complex features, on the other hand, update calls are overridden by the features' custom behavior, meaning that the feature's store method will be called even if an update cursor is used.
0 Kudos