Unable to Update feature attributes

805
4
07-18-2011 10:08 PM
SunilJammalamadaka
New Contributor
This is what i've done in my arcmap class library:


ESRI.ArcGIS.esriSystem.IPropertySet propertySet = new ESRI.ArcGIS.esriSystem.PropertySetClass();

                propertySet.SetProperty("SERVER", "172.16.8.148");
                propertySet.SetProperty("INSTANCE", "ESRI_SDE");
                propertySet.SetProperty("DATABASE", "ARCGIS_SCADA");
                propertySet.SetProperty("USER", "sde");
                propertySet.SetProperty("PASSWORD", "smartgrid");
                propertySet.SetProperty("VERSION", "SDE.DEFAULT");
                propertySet.SetProperty("AUTHENTICATION_MODE", "DBMS");

IWorkspaceFactory workspaceFactory = new ESRI.ArcGIS.DataSourcesGDB.SdeWorkspaceFactoryClass();
                IWorkspace workspace = workspaceFactory.Open(propertySet, 0);
                try
                {
                    //Cast to IFeatureWorkspace.
                    IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace;
                    IFeatureClass featureClass = featureWorkspace.OpenFeatureClass("SDE.SCADA_FINAL_CB");
                  
                    //Cast to IFeatureWorkspace.
                    IWorkspaceEdit workspaceEdit = (IWorkspaceEdit)workspace;
                    workspaceEdit.StartEditing(true);

                    // Start an edit operation and create a cursor.
                    workspaceEdit.StartEditOperation();

                    if (workspaceEdit.IsBeingEdited())
                    {
                        // Find the index of the field to edit.
                        int typeFieldIndex = featureClass.FindField("STATE");
                       
                        IQueryFilter queryFilter = null;
                        IFeatureCursor searchCursor = null;
                        IFeature feature = null;

                            queryFilter = new QueryFilterClass();
                            queryFilter.WhereClause = "OBJ_NAME='object'";
                            searchCursor = featureClass.Update(queryFilter, false);

                          
                            while ((feature = searchCursor.NextFeature()) != null)
                            {
                                feature.set_Value(typeFieldIndex, o.Value);
                                feature.Store();
                                searchCursor.UpdateFeature(feature);
                                // Since the edit operation is ending, release the cursor.
                                Marshal.ReleaseComObject(searchCursor);                

                            }

                        mxDoc.ActiveView.Refresh();

                         //Stop the edit operation.
                        workspaceEdit.StopEditOperation();
                        workspaceEdit.StopEditing(true);
                       
                    }
                }

now if i see the arcmap and check out the feature for update(value change in field), im not getting the updated one.
If i click "start editing" from the editor dropdown menu, im able to find the update in attributes table. It is working even if the arcmap window is closed and opened again.
I want to get the updates without any manual operation.
0 Kudos
4 Replies
NeilClemmons
Regular Contributor III
It could be because you're calling Store and UpdateFeature.  Use one or the other but not both.  I would suggest UpdateFeature.
0 Kudos
SunilJammalamadaka
New Contributor
Hi Neil,

I removed the store method and kept Updatefeature like you said. It didn't fix the problem. Only after restarting the arcmap window(mxd), the feature attribute is getting updated.
0 Kudos
NeilClemmons
Regular Contributor III
A couple of other things - you're passing in True to StartEditing.  If you're not implementing undo/redo capability then I would pass in False.  Also, when running code in ArcMap I use the Editor extension (IEditor) to manage the edit session instead of IWorkspaceEdit.
0 Kudos
SunilJammalamadaka
New Contributor
Ok... but, i never worker on iEditor. Should I send the same defined workspace(as in my code) as a parameter to IEditor.startOperation() method?
0 Kudos