How do change field length with arcobject

468 views Asked by At

I want to change some string field in sdegeodatabse with bellow code. The code are running without any problem. but after running, filed length return to default length. What am i missing?

static void writetablecode(IDataset dataset)
        {
            ITable table = dataset as ITable;

            IFieldsEdit fields = table.Fields as IFieldsEdit;
            for (int i = 0; i < fields.FieldCount; i++)
            {
                IFieldEdit field = fields.Field[i] as IFieldEdit;
                if (field.Type==esriFieldType.esriFieldTypeString & field.Length<30 )
                {
                    field.Length_2  = 30;
                }

            }
        }
1

There are 1 answers

0
Koen On BEST ANSWER

It is not possible to edit the length of a field, the only way to achieve this is to create a new field, copy the data to the new field. http://support.esri.com/de/knowledgebase/techarticles/detail/42783

IFieldEdit shouldn't be used to change existing fields anyway. From the API reference:

The IFieldEdit interface is used when creating new fields. You should not use it to modify fields, for that purpose use IClassSchemaEdit. In general, when modifying fields, the restrictions that apply in ArcCatalog also apply in ArcObjects; for example, you cannot change the name or type of a field.