0

我编写了这段代码(在 C# .net 中使用 Arcobjcts)从我的表中读取记录:

 ITable table =featureWorkspace1.OpenTable(featureClass1.AliasName);
 List<String> list2 = new List<String>();
 ITableSelection tableSelection = table as ITableSelection;
 ISelectionSet2 selectionSet = tableSelection.SelectionSet as ISelectionSet2;
 ICursor Cursor = null;
 IFeatureCursor featureCursor = Cursor as IFeatureCursor;
 selectionSet.Search(null, true, out Cursor);
 int fieldIndex = featureCursor.Fields.FindField(champ);
 list2.Add(fieldIndex.ToString());
 this.listBox2.DataSource = list2;

但是会出现错误:

对象引用未设置为对象的实例

我也试过:

 IQueryFilter queryFilter = new QueryFilterClass();
 queryFilter.WhereClause = " champ <> '' ";
 ICursor      Cursor = table.Search(queryFilter,true);
 IRow city = Cursor.NextRow();
 while (city != null)
 {
     list2.Add((String)(city.Value[fieldIndex].ToString()));
     city = Cursor.NextRow();
 }    
 this.listBox2.DataSource = list2;

错误是:

HRESULT 0x80040358 的异常

你能帮我解决这两个问题之一吗?

4

1 回答 1

1

在调用它之前检查值city.Value[fieldIndex]并确保它是。!= System.DBNull.Value.ToString()

我还将验证您的字段索引是否正确以及您要查询的字段是否champ拼写正确。

于 2014-07-09T17:56:18.380 回答