简体   繁体   English

从ArcObjects C#中的表读取记录

[英]Reading record from table in arcobjects c#

I wrote this code (in C# .net using Arcobjcts) to read record from my table: 我编写了这段代码(在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;

But an error occurs: 但是会发生错误:

an object reference not set to an instance of an object 没有设置为对象实例的对象引用

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;

The error was: 错误是:

Exception from HRESULT 0x80040358 来自HRESULT的异常0x80040358

Can you please help me how to fix one of those two problems? 您能帮我解决这两个问题之一吗?

Check the value in city.Value[fieldIndex] and make sure it is != System.DBNull.Value before calling .ToString() on it. 在对.ToString()进行调用之前,请检查city.Value[fieldIndex]的值,并确保其为!= System.DBNull.Value

I would also verify that your field index is correct and that the field you are querying for champ is spelled correctly. 我还将验证您的字段索引正确,并且您要查询champ的字段的拼写是否正确。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM