arcengine 属性表添加字段

       /// <summary>
        /// 添加字段
        /// </summary>
        /// <param name="layer"></param>
        /// <param name="fieldName"></param>
        /// <param name="filedType"></param>
        /// <param name="fieldLength"></param>
        /// <returns></returns>
        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;
            }

        }

 

转载自:https://blog.csdn.net/tianxinzhe032/article/details/6660006

You may also like...