AnsweredAssumed Answered

Open a table from a file geodatabase

Question asked by jerome.garnon on Mar 30, 2020
Latest reply on Mar 31, 2020 by jerome.garnon

Hello,

I (Jerome, first post on this forum I believe) am currently building an ArcObjects SDK tool with visual studio for ArcGIS desktop 10.5.1, and I am struggling with a simple (at least it sounds simple) task: open a table from a geodatabase to have access to the data it contains... I get the geodatabase from a reference featureclass (flLocation).

 

I've tried:

'##################################

Public Function GetTable(ByVal sTableName As String) As ITable


Dim pWorkspaceFactory As IWorkspaceFactory = New ESRI.ArcGIS.DataSourcesGDB.FileGDBWorkspaceFactory
Dim pDataset As IDataset = CType(flLocation, IDataset)
Dim pWksp As IWorkspace = pDataset.Workspace
Dim sGdbPath As String = pWksp.PathName
Dim pWorkSpace As IWorkspace = pWorkspaceFactory.OpenFromFile(sGdbPath, 0)


Dim pEnumDataset As IEnumDataset = pWorkSpace.Datasets(esriDatasetType.esriDTTable)

pEnumDataset.Reset()


Dim pTable As ITable
pTable = pEnumDataset.Next


Dim pFTable As ITable
Do While Not pTable Is Nothing
   If TypeOf pTable Is ITable Then    
      If pTable.Name = sTableName Then
         pFTable = TryCast(pTable, ITable)
         Exit Do
      End If
   End If
   pTable = pEnumDataset.Next
Loop

Return pFTable

End Function

'##################################

 

I keep having an error at "If pTable.Name = sTableName" with the traditional message "Exception thrown: 'System.NullReferenceException' in Microsoft.VisualBasic.dll, Additional information: Object reference not set to an instance of an object." but I cannot make it work adding a "new" statement or "Not (IsDBNull(pTable))" for example...

 

Any help would be much appreciated,

Thank you

Jerome

Outcomes