This document is archived and information here might be outdated.  Recommended version.


Parsing table and field names (ArcObjects .NET 10.4 SDK)

Parsing table and field names


About parsing table and field names

Programs should use the geoprocessor ParseTableName and ParseFieldName methods to split the fully qualified names for a dataset or for a column in a table into its components (database, owner, table, and column). Programs that need to be relational database management system (RDBMS) independent should not assume that a period ('.') is the delimiter used to separate the components of a fully qualified dataset name.
ArcGIS applications always use fully qualified names, so if your program is being used as the source of a script tool, any feature class name, for example, must be parsed if the program is to determine the name of the feature class without the user and database names.
In the following code example, the program checks the input feature class for specific user names. The program could use the parsing functions of C# or VB.NET to split the qualified name, but it would then assume a specific syntax, which can change if another database type is used.
ParseTableName returns a single string with the database name, owner name, and table name separated by commas. ParseFieldName returns the table name and the field name, also separated by commas. A program can then reliably parse the returned string, since these methods always return the same formatted string. A string in C# or VB.NET has a number of native methods for manipulation.
In the following code example, the split method is used to create a string array, using the comma as the delimiter:
[C#]
public void ExampleGPParseTableName(Geoprocessor GP)
{

    // Set the workspace. 
    GP.SetEnvironmentValue("workspace", @"Database Connections\hemlock.sde");

    // Parse the table name and print the components.
    string parsetable=GP.ParseTableName("ESRITYPE.ESRICNTRY94", "");
    string[] split=parsetable.Split(new Char[]
    {
        ',', '.'
    }
    );

    foreach (string s in split)
    {

        if (s.Trim() != "")
            Console.WriteLine(s);

    }

}
[VB.NET]
Public Sub ExampleGPParseTableName(ByVal GP As Geoprocessor)
    
    ' Set the workspace.
    GP.SetEnvironmentValue("workspace", "Database Connections\hemlock.sde")
    
    ' Parse the table name and print the components.
    Dim parsetable As String=GP.ParseTableName("ESRITYPE.ESRICNTRY94", "")
    Dim Split As String()=parsetable.Split(New Char() {","c, "."c})
    
    For Each s As String In Split
        
        If s.Trim() <> "" Then
            
            Console.WriteLine(s)
            
        End If
        
    Next s
    
End Sub


See Also:

Geoprocessing considerations for ArcSDE data




To use the code in this topic, reference the following assemblies in your Visual Studio project. In the code files, you will need using (C#) or Imports (VB .NET) directives for the corresponding namespaces (given in parenthesis below if different from the assembly name):