从对象表中读取记录

本文关键字:读取 记录 对象 | 更新日期: 2023-09-27 18:03:34

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

 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;

但是出现错误:

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

Also I tried:

 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异常

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

从对象表中读取记录

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

我还将验证您的字段索引是否正确,并且您正在查询的champ字段拼写是否正确。