ArEngine添加、删除属性表字段

  ///   
    /// 删除属性表字段  
    ///   
    /// 需要添加字段的IFeatureLayer  
    /// 添加的字段的名称  
    ///   
    static public bool DeleteField(IFeatureLayer layer, string fieldName)  
    {  
        try  
        {  
            ITable pTable = (ITable)layer;  
            IFields pfields;  
            IField pfield;  
            pfields = pTable.Fields;  
            int fieldIndex = pfields.FindField(fieldName);  
            pfield = pfields.get_Field(fieldIndex);  
            pTable.DeleteField(pfield);  
            return true;  
        }  
  
  
        catch (Exception ex)  
        {  
            return false;  
        }  
    }  

///   
 /// 添加字段  
 ///   
 ///   
 ///   
 ///   
 ///   
 ///   
 static public bool AddField(IFeatureLayer layer, string fieldName, esriFieldType filedType, int fieldLength)  
 {  
     try  
     {  
         IFields pFields = layer.FeatureClass.Fields;  
         // IFieldsEdit pFieldsEdit = pFields as IFieldsEdit;  
         IFieldEdit pFieldEdit;  
  
         pFieldEdit = new FieldClass();  
         if (fieldName.Length > 5)  
             pFieldEdit.Name_2 = fieldName.Substring(0, 5);  
         else  
             pFieldEdit.Name_2 = fieldName;  
         pFieldEdit.Type_2 = filedType;  
         pFieldEdit.Editable_2 = true;  
         pFieldEdit.AliasName_2 = fieldName;  
         pFieldEdit.Length_2 = fieldLength;  
         ITable pTable = (ITable)layer;  
         pTable.AddField(pFieldEdit);  
         return true;  
         //   pFieldsEdit.AddField((IField)pFieldEdit);  
     }  
  
  
     catch (Exception ex)  
     {  
         return false;  
     }  
  
 }  

你可能感兴趣的:(ArcEngine)