我写了添加字段的代码, public static void AddField_IClass(IFeatureClass featureClass, string fieldName, string aliasName,
esriFieldType type, int fieldLen, int precision, bool allowNull)
{
if (featureClass == null || fieldName == null || fieldName.Trim() == "")
return;
IFields pFields = featureClass.Fields;
if (pFields.FindField(fieldName) >= 0)
return;
IClass pClass = featureClass as IClass;
IFieldsEdit pFieldsEdit = pFields as IFieldsEdit;
IField pField = new FieldClass();
IFieldEdit pFieldEdit = pField as IFieldEdit;
try
{
addFiled(ref pFieldEdit, fieldName, aliasName, type, fieldLen, precision, allowNull);
/***********出错位置****************/
pClass.AddField(pField);
}
catch (Exception e)
{
throw e;
}
}
private static void addFiled(ref IFieldEdit fieldEdit, string fieldName, string aliasName, esriFieldType type, int fieldLen, int precision, bool allowNull)
{
try
{
fieldEdit.Name_2 = fieldName;
if (aliasName != null && aliasName.Trim() != "")
fieldEdit.AliasName_2 = aliasName;
fieldEdit.Type_2 = type;
fieldEdit.Length_2 = fieldLen;
if (type == esriFieldType.esriFieldTypeDouble || type == esriFieldType.esriFieldTypeSingle)
{
fieldEdit.Precision_2 = precision;//小数位数
}
fieldEdit.IsNullable_2 = allowNull;
}
catch (Exception e)
{
throw e;
}
}
请教一下,我批量为图层创建字段,同样的字段在有些图层中能创建成功,有些就会把错,这是为什么呢?我跟踪看了一下,每个变量的值都存在。