0

I need to mapping different field values in an attribute table. The attribute table as follows:

enter image description here

For example, I want to get the "DrainName" value when "BQ no." = "22/22" and "Segment ID" = "22/22-1". The result should return 2 values.

Is there a way vb.net to do this? Thanks.

  • Are you just trying to 'select' those two values? – Michael Stimson Sep 18 '14 at 3:50
  • Hi Michael, select these two values is my current design. Later I may also need to mapping the whole table. – ppLily Sep 18 '14 at 3:51
1

Following on from the previous arcpy SearchCursor return a OBJECTID value not as an integer

Dim pQF As ESRI.ArcGIS.Geodatabase.IQueryFilter = New ESRI.ArcGIS.Geodatabase.QueryFilter()
pQF.WhereClause = "BQ no. = '22/22' and Segment ID = '22/22-1'" 'exactly the same as Select by Attributes'
Dim pCur As ESRI.ArcGIS.Geodatabase.ICursor = pTable.Search(pQF, False) ' open the cursor'
Dim pFieldIndex As Integer = pTable.Fields.FindField("DrainName") ' get the index of the field "DrainName" or -1 if it's not found
Dim pRow As ESRI.ArcGIS.Geodatabase.IRow = pCur.NextRow ' first row'
Do Until pRow Is Nothing
    Debug.Print(pRow.Value(pFieldIndex)) ' do something important here'
    pRow = pCur.NextRow
Loop

To limit the returned rows use IQueryFilter interface (or ISpatialFilter - another handy one if you want to select by location).

In VB you get the value by its index not the field name; to get the index use ITable.Fields.FindField (IFeatureClass.Fields.FindField is the same) to get the index.

I have a feeling that you have field aliases and not field names, that might cause problems with the whereclause of the query - use the field names instead for better results.

  • Hi Michael you are so nice, thank you very much for the help. I will follow your instruction. Yes I have field aliases, will pay attention when use it in the query. – ppLily Sep 18 '14 at 4:06
  • 1
    It might work, I don't know. I don't use field aliases. I would do Select by attributes in ArcMap on the table and if I like the results then copy the query from the window and put quote marks around it for the where clause - that always works for me. – Michael Stimson Sep 18 '14 at 4:09
  • Thanks Michael. any hints of mapping the whole table? I feel there should have a GP to mapping fields for the whole table, but so sad I haven't found it. – ppLily Sep 18 '14 at 4:12
  • 1
    to do the whole table go back to pTable.Search(Nothing,False) - Nothing means everything, it's a bit counter-intuitive but works. – Michael Stimson Sep 18 '14 at 4:16
  • Hi Michael, I use the code you provide to read data from a dbf file. I find if I do some simple thing in the loop, the map just crash once all values retrieved correctly. I open a new question as follows: gis.stackexchange.com/questions/114937/… , if possible, can please have a look? many thanks. – ppLily Sep 24 '14 at 6:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.