How do I get all of the tableNames from the FGDB in ArcGIS Pro SDK

1249
8
Jump to solution
03-10-2022 02:05 AM
by Anonymous User
Not applicable

Hi,

I'm working on an add-in that supports both .sde and fgdb DB connections. Although I can retrieve all of the table names when I connect to the .sde database, I'm not sure how I can do the same when I connect to the FGDB.

The code below shows how I connect to the .sde DB and retrieve tableNames from it.

ShabinaBano_0-1646906449971.png

Could someone please help me in retrieving all of the table names when I connect to FGDB?

 

Thanks in advance!!

0 Kudos
1 Solution

Accepted Solutions
GKmieliauskas
Esri Regular Contributor

Hi,

In both cases sde and gdb you should use the same way to get table names. Only database opening differs.

            // For sde
            DatabaseConnectionFile connector = new DatabaseConnectionFile(new Uri(sdePath));
            // For gdb
            FileGeodatabaseConnectionPath connector  = new FileGeodatabaseConnectionPath(new Uri(gdbPath));
            // coomon part
            using (Geodatabase gdb = new Geodatabase(connector))
            {
                var defs = gdb.GetDefinitions<TableDefinition>();
                foreach (var d in defs)
                {
                    string dsName = d.GetName();
                    // your code here
                    d.Dispose();
                }
            }

View solution in original post

8 Replies
GKmieliauskas
Esri Regular Contributor

Hi,

In both cases sde and gdb you should use the same way to get table names. Only database opening differs.

            // For sde
            DatabaseConnectionFile connector = new DatabaseConnectionFile(new Uri(sdePath));
            // For gdb
            FileGeodatabaseConnectionPath connector  = new FileGeodatabaseConnectionPath(new Uri(gdbPath));
            // coomon part
            using (Geodatabase gdb = new Geodatabase(connector))
            {
                var defs = gdb.GetDefinitions<TableDefinition>();
                foreach (var d in defs)
                {
                    string dsName = d.GetName();
                    // your code here
                    d.Dispose();
                }
            }
by Anonymous User
Not applicable

@GKmieliauskas I don't know why but the above code is not working as expected..'defs' is coming as 0 (count = 0)

Is anything else I need to add??

0 Kudos
GKmieliauskas
Esri Regular Contributor

Is code not working with sde or gdb or both?

0 Kudos
by Anonymous User
Not applicable

Is this the same way we can fetch the columnNames also?

 

0 Kudos
GKmieliauskas
Esri Regular Contributor

Do you mean table fields?

0 Kudos
by Anonymous User
Not applicable

Yes the fields name.

0 Kudos
GKmieliauskas
Esri Regular Contributor

From Table of FeatureClass definition you can get Fields:

var fields = d.GetFields();
foreach (var x in fields)
{
    string fieldName = x.Name;
}

Place after line 12 in code above

 

0 Kudos
by Anonymous User
Not applicable

@GKmieliauskasworked perfectly for me Actually, I was missing a minor detail  QuesuedTask.
I can see the count  now.

 

Thanks a lot! 🙂

0 Kudos