在爲現有要素類新增字段時,有可能會爆出該表正被其餘程序或其餘人使用,這時咱們就會添加失敗,解決辦法以下:it
在新增字段以前,先修改SchemaLock的狀態table
ISchemaLock pSchemaLock = m_pOriginFeatureClass as ISchemaLock;
pSchemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);程序
而後再新增字段tab
//Add New Field
int nIndexOfGBTYPE = m_pOriginFeatureClass.Fields.FindField("GB_TYPE");
if (nIndexOfGBTYPE == -1)
{
IField pField = new FieldClass();
IFieldEdit pFieldEdit = pField as IFieldEdit;
pFieldEdit.Name_2 = "GB_TYPE";
pFieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
pFieldEdit.IsNullable_2 = true;
pFieldEdit.AliasName_2 = "GB_TYPE";
pFieldEdit.DefaultValue_2 = "";
pFieldEdit.Editable_2 = true;
pFieldEdit.Length_2 = 100;
m_pOriginFeatureClass.AddField(pField);
}di
//最後進行恢復處理new
pSchemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);ab