AE+C# 错误:A requested feature object could not be located.
我想遍历属性表,添加一列数值,新建字段后在遍历时出现错误。
出现这问题的原因是:我遍历要素类里的要素的某一属性值时,使用的是`IFeature pFeature = pFeatureClass.GetFeature(i);
for (int i = 0; i < pFeatureClass.FeatureCount(null); i++)
{
IFeature pFeature = pFeatureClass.GetFeature(i);
pFeature.set_Value(pFeature.Fields.FindField(textBox5.Text), list1[i]); //每个要素的“A”字段存储的都是“B”。
pFeature.Store();
}
应该使用
IFeatureCursor pFeatureCursor = pFeatureLayer.Search(null , false);
IFeature pFeature=pFeatureCursor .NextFeature ();
for (int i=0;i <List1 .Count;i ++)
{
pFeature.set_Value(pFeature.Fields.FindField(textBox1 .Text ), List1[i]);
pFeature.Store();//一定要加store才能保存到属性表中
pFeature = pFeatureCursor.NextFeature();
}