首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

Objects in this class cannot be updated outside an edit session,该如何解决

2013-11-26 
Objects in this class cannot be updated outside an edit session求救:Objects in this class cannot be

Objects in this class cannot be updated outside an edit session
求救:Objects in this class cannot be updated outside an edit session
http://blog.csdn.net/mydriverc/article/details/1799749这里说的方法是:
licenseStatus = CheckOutLicensesesriLicenseProductCode.esriLicenseProductCodeEngineGeoDB
这好像是VB的方法 
而我用的C#、界面框架是wpf
arcengine版本是10.0
在程序入口app.xaml.cs获取权限的方法是:


AoInitialize aoi = new AoInitializeClass ();
esriLicenseProductCode productCode= esriLicenseProductCode.esriLicenseProductCodeEngineGeoDB;
aoi.Initialize(productCode);

但是还是提示相同的错误

具体提示错误的地方如下: 
其中提示错误的语句:IFeatureCursor pFeaCursor = fcSde.Insert(true);

public void ImportShpToSde(IFeatureClass fcShp, IWorkspace inWorkspace, IFeatureClass fcSde, Cread.Model.Regularity regularity)
        {
            FeatureRegularity FeatureRegularity = regularity as FeatureRegularity; 
            IList<Regularity> FieldRegularities = FeatureRegularity.FieldRegularityCollection;
            IDictionary<string, string> fieldDic = new Dictionary<string, string>();
            if (FieldRegularities != null)
            {
                foreach (Regularity fg in FieldRegularities)
                {
                    Cread.Model.Field fromField = fg.from as Cread.Model.Field;
                    Cread.Model.Field toField = fg.to as Cread.Model.Field;
                    string fName = fromField.FieldName;
                    string tName = toField.FieldName;
                    if (fName != tName)
                    {
                        fieldDic.Add(fName, tName);
                    }
                } 
            } 
            IQueryFilter queryFilter = new QueryFilterClass();
            queryFilter.WhereClause = FeatureRegularity.Filter;

            IFeatureCursor pFeaCursor = fcSde.Insert(true);
            IFeatureBuffer pFeaBuffer = fcSde.CreateFeatureBuffer();

            IFields fields;
            IEnumFieldError pFieldError;
            IFieldChecker pFieldChecker = new FieldCheckerClass();
            pFieldChecker.ValidateWorkspace = inWorkspace;
            pFieldChecker.Validate(fcShp.Fields, out pFieldError, out fields);

            IField pField = new FieldClass();
            IFeature pFeature = null;
            int iIndex = 0;
            long n = 0;
            for (int i = 0; i < fcShp.FeatureCount(queryFilter); i++)
            {
                pFeature = fcShp.GetFeature(i);
                try
                {
                    pFeaBuffer = fcSde.CreateFeatureBuffer(); 


                    //添加字段值
                    for (int j = 0; j < fields.FieldCount; j++)
                    {
                        pField = fields.get_Field(j);
                        string pFieldName = pField.Name;
                        if (fieldDic.ContainsKey(pFieldName))
                        {
                            iIndex = pFeaBuffer.Fields.FindField(fieldDic[pFieldName]);  
                        }
                        else
                        {
                            iIndex = pFeaBuffer.Fields.FindField(pFieldName);  
                        }
                        if (iIndex != -1)
                        {
                            pFeaBuffer.set_Value(iIndex, pFeature.get_Value(j));
                        }
                    }
                    pFeaCursor.InsertFeature(pFeaBuffer);
                }
                catch (System.Exception ex)
                { 
                    return;
                }
                finally
                {
                    n++;
                    if (n % 100 == 0)
                    {
                        pFeaCursor.Flush();
                    }
                }
                pFeaCursor.Flush();
            }
        }



arcengine geodatabase权限 oracle sde直连sde库
[解决办法]
破了没有?
//启动SDE的编辑
                    IWorkspaceEdit workSpaceEdit = sdeWorkspace as IWorkspaceEdit;


                    workSpaceEdit.StartEditing(false);
                    workSpaceEdit.StartEditOperation();

应该是没有启动编辑的原因

热点排行