In this topic
- Returning rows from a table
- Accessing data stored in a row
- Accessing geometry stored in a table
- Accessing coded values
To use the code in this topic, add a reference to ESRI.ArcGISExplorer.dll and also add the following namespace reference via using (C#) or Imports (VB .NET) statements:
- ESRI.ArcGISExplorer.Data
-
ESRI.ArcGISExplorer.Geometry
Returning rows from a table
The following table shows options for returning rows in a table:
Aim
|
Table method
|
Return type
|
Returns a single row by unique object identifier.
|
||
Returns multiple rows by unique object identifiers.
|
||
Returns the rows that satisfy a query.
|
||
Returns all rows.
|
The following code example shows how to use the methods previously described to return rows from a table:
For information on querying tables, see How to search a table.
Table mountains = Table.OpenFileGeodatabaseTable(@"C:\Data\Scotland.gdb",
"mountains");
//Example 1—Returns a single row for the specified OBJECTID.
Row singleRow = mountains.GetRow(231);
//Example 2—Returns multiples rows for the specified OBJECTIDs.
RowCollection rowsByOID = mountains.GetRows(new int[]
{
1, 2, 3
}
);
//Example 3—Returns multiple rows that satisfy the query.
RowCollection rowsByQuery = mountains.Search(new Filter("NAME LIKE 'B%'"));
//Example 4—Returns all rows.
RowCollection rows = mountains.GetRows();
[VB.NET]
Dim parcels As Table = Table.OpenFileGeodatabaseTable("C:\Data\Scotland.gdb", "mountains")
'Example 1—Returns a single row for the specified OBJECTID.
Dim singleRow As Row = mountains.GetRow(231)
'Example 2—Returns multiples rows for the specified OBJECTIDs.
Dim rowsByOID As RowCollection = mountains.GetRows(New Integer() {1, 2, 3})
'Example 3—Returns multiple rows that satisfy the query.
Dim rowsByQuery As RowCollection = mountains.Search(New Filter("NAME LIKE 'B%'"))
'Example 4—Returns all rows.
Dim rows As RowCollection = mountains.GetRows()
Accessing data stored in a row
You can use the Row.Values property to return a RowValueCollection object containing all the values for a row. The collection stores each value as an object that can be cast to match the appropriate ColumnType or converted to a string using the ToString method.
The following code example shows how to access the values in the collection by index or column name:
[C#]
//Get the RowValueCollection for a single row.
RowValueCollection values = singleRow.Values;
//Example 1—Print all the values for each row, including the corresponding column names.
for (int i = 0; i < values.ColumnCount; i++)
{
//Get the name of the column.
string columnName = values.Columns[i].Name;
//Get the actual value stored in the table.
string rowValue = values[i].ToString();
//Print the column name and the value for every column in this row.
System.Diagnostics.Debug.Print(string.Format(
"Column Name: {0}, Row Value: {1}",
columnName, rowValue));
}
//Example 2—Return the actual value for a specific column.
int typeValue = (int)values["MountainType"];
System.Diagnostics.Debug.Print(typeValue.ToString()); //Prints 0.
[VB.NET]
'Get the RowValueCollection for a single row.
Dim values As RowValueCollection = singleRow.Values
'Example 1—Print all the values for each row, including the corresponding column names.
For i As Integer = 0 To values.ColumnCount - 1
'Get the name of the column.
Dim columnName As String = values.Columns.Item(i).Name
'Get the actual value stored in the table.
Dim rowValue As String = values.Item(i).ToString()
'Print the column name and the value for every column in this row.
System.Diagnostics.Debug.Print(String.Format("Column Name: {0}, Row Value: {1}", columnName, rowValue))
Next i
'Example 2—Return the actual value for a specific column.
Dim typeValue As Integer = DirectCast(values.Item("MountainType"), Integer)
System.Diagnostics.Debug.Print(typeValue.ToString()) 'Prints 0.
Accessing geometry stored in a table
A spatially enabled table, namely, one instantiated for a shapefile or geodatabase feature class, always contains a spatial column that is used to store the geometry for each row. Like all other column types, the geometry for a row can be returned from the RowValueCollection, or alternatively, it can be returned directly using the Row.Geometry property. See the following code example:
[C#]
//Return geometry stored in row.
Geometry geom = values[parcels.Columns.SpatialColumnName] as Geometry;
//Return geometry using convenience property.
geom = singleRow.Geometry;
[VB.NET]
'Return geometry stored in row.
Dim geom As Geometry = DirectCast(values.Item(parcels.Columns.SpatialColumnName), Geometry)
'Return geometry using convenience property.
geom = singleRow.Geometry
Accessing coded values
A column in a geodatabase table or feature class might have an associated coded value domain. For example, the domain shown in the following table classifies mountains according to their height:
MtnType coded value domain
|
|
Code (long integer)
|
Description (string)
|
0
|
Munro
|
1
|
Corbett
|
2
|
Other
|
The domain has been defined against the "MountainType" column of the "Mountains" feature class; therefore, you might want to access both the stored integer values or the associated descriptive strings.
- To return a value, use the approach previously described in the Accessing data stored in a row section.
- To return a domain value description, use the GetCodedName method.
See the following code example:
[C#]
//Return the coded value for a specific column that has domain defined.
string typeCodedDomainValue = (string)values.GetCodedName("MountainType");
System.Diagnostics.Debug.Print(typeCodedDomainValue); //Prints "Munro."
[VB.NET]
'Return the coded value for a specific column that has domain defined.
Dim typeCodedDomainValue As String = values.GetCodedName("MountainType")
System.Diagnostics.Debug.Print(typeCodedDomainValue) 'Prints "Munro."
The GetCodedName method can also be used to retrieve subtype descriptions if a geodatabase table or feature class has been subtyped.