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);
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();
}
}
//启动SDE的编辑应该是没有启动编辑的原因
IWorkspaceEdit workSpaceEdit = sdeWorkspace as IWorkspaceEdit;
workSpaceEdit.StartEditing(false);
workSpaceEdit.StartEditOperation();