Select to view content in your preferred language

Field of type esriFieldTypeOID is not editable within a new RecordSet

1323
1
08-09-2011 07:40 AM
MCMADMIN
Emerging Contributor
Building a new RecordSet with a field of esriFieldType.esriFieldTypeOID and Editable = true is not editable at all! This fieldtype implies obviously, that the field can't be edited. If you use esriFieldType.esriFieldTypeInteger instead, it works fine.

Example:
// define new recordset with cols id and txt
IRecordSet rs = new RecordSet();
IRecordSetInit rsDefinition = rs as IRecordSetInit;
IFields rsFields = new Fields();
IFieldsEdit rsFieldsEdit = rsFields as IFieldsEdit;
rsFieldsEdit.FieldCount_2 = 2;
IField rsField = new ESRI.ArcGIS.Geodatabase.Field();
IFieldEdit rsFieldEdit = rsField as IFieldEdit;
rsFieldEdit.Name_2 = "id";
//rsFieldEdit.Type_2 = esriFieldType.esriFieldTypeOID; <<< is not editable!!!
rsFieldEdit.Type_2 = esriFieldType.esriFieldTypeInteger; //<<< use Integer instead
rsFieldEdit.Editable_2 = true; // doesn't make esriFieldTypeOID editable!!!
rsFieldsEdit.set_Field(i, rsField);
rsField = new ESRI.ArcGIS.Geodatabase.Field();
rsFieldEdit = rsField as IFieldEdit;
rsFieldEdit.Name_2 = "txt";
rsFieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
rsFieldEdit.Length_2 = 80;
rsFieldEdit.Editable_2 = true;
rsFieldsEdit.set_Field(i, rsField);
rsDefinition.CreateTable(rsFields);

ICursor rsCursor = rsDefinition.Insert();
IRowBuffer rowBuffer = rsDefinition.CreateRowBuffer();
rowBuffer.set_Value(0, 1); // throws execption if esriFieldTypeOID is used!!!
rowBuffer.set_Value(1, "blabla");

Bug or feature? Even if the created Recordset never will be stored in a DB, you can't use e.g. field definitions from an existing table, but have to replace esriFieldTypeOID with esriFieldTypeInteger.
(AGS 10 SDK)
0 Kudos
1 Reply
MelitaKennedy
Esri Notable Contributor
OIDs are maintained by ArcGIS to ensure an unique identifier per feature. So a field marked as esriFieldTypeOID won't be editable.

Fundamentals of ObjectID Fields

Melita
0 Kudos