aviabunin

How to clear contents of layer?

Discussion created by aviabunin on Mar 21, 2011
Latest reply on Mar 23, 2011 by Neil
(C#+ .NET+ arcgis Engine.)
I use next cod for clear contents of layer:
        public void clearSetOfFeatures() {

            ESRI.ArcGIS.Geodatabase.IQueryFilter qFilter = new ESRI.ArcGIS.Geodatabase.QueryFilter();
            qFilter.WhereClause = "";
            qFilter.SubFields = "name";

            ESRI.ArcGIS.Geodatabase.IFeatureClass featureClass = null;
            int indOfLayer = getIndexLayerByName("chs2011");
            ESRI.ArcGIS.Carto.IFeatureLayer featureLayer = axTOCControl1.ActiveView.FocusMap.get_Layer(indOfLayer) as ESRI.ArcGIS.Carto.IFeatureLayer;
            ESRI.ArcGIS.Geodatabase.IFeatureCursor cursor = featureLayer.Search(qFilter, true);
            
            featureClass = featureLayer.FeatureClass;
            ESRI.ArcGIS.Geodatabase.IFeature feature =null;

            // Create a ComReleaser for cursor management.
            using (ESRI.ArcGIS.ADF.ComReleaser comReleaser = new ESRI.ArcGIS.ADF.ComReleaser())
            {
                // Create and manage a cursor.
                ESRI.ArcGIS.Geodatabase.IFeatureCursor searchCursor = featureClass.Search(qFilter, false);
                comReleaser.ManageLifetime(searchCursor);

                // Delete the retrieved features.

                while ((feature = searchCursor.NextFeature()) != null)
                {
                    {
                        feature.Delete();
                    }
                }
            }
        }

But sometimes I get error message - row count is not equal to feature count. And I must recreate layer. What is wrong?
Thank you for any help!

Outcomes