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.
Could someone please help me in retrieving all of the table names when I connect to FGDB?
Thanks in advance!!
Solved! Go to Solution.
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();
}
}
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();
}
}
@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??
Is code not working with sde or gdb or both?
Is this the same way we can fetch the columnNames also?
Do you mean table fields?
Yes the fields name.
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
@GKmieliauskasworked perfectly for me Actually, I was missing a minor detail QuesuedTask.
I can see the count now.
Thanks a lot! 🙂