AnsweredAssumed Answered

Problems starting an edit session in .Net

Question asked by cwharrison on Mar 10, 2015

I am trying to create an update cursor to a feature class, but keep getting the exception "Objects in this class cannot be updated outside an edit session ".  I have this workign in arcpy, but cant seem to make it work with the .Net.  What am I missing?

 

Thanks!

 

            RuntimeManager.BindLicense(ProductCode.Desktop);

            IWorkspace wks;

            Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.SdeWorkspaceFactory");

            IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType) ;

            wks = workspaceFactory.OpenFromFile("c:\\temp\\my.sde", 0);

 

 

            IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)wks;

 

 

            IFeatureClass featureClass = featureWorkspace.OpenFeatureClass("MyFeatureClass");

 

 

          try

          {

 

 

              IWorkspaceEdit workspaceEdit = (IWorkspaceEdit)wks;

              workspaceEdit.StartEditing(true);

              workspaceEdit.StartEditOperation();

 

 

 

 

              Debug.WriteLine("There are " + featureClass.FeatureCount

                (null) + " rows");

 

 

              IQueryFilter queryFilter = new QueryFilterClass();

              queryFilter.WhereClause = "AField= 'testValue'";

 

               //generated exception "Objects in this class cannot be updated outside an edit session "

              IFeatureCursor updateCursor = featureClass.Update(queryFilter, true);

 

 

          }

          catch (Exception ex)

          {

 

 

          }

           

;

Outcomes