thaluska

add table to map document from geodatabase

Discussion created by thaluska on Feb 9, 2011
Latest reply on Feb 10, 2011 by thaluska
Hello:
I'm new to vb and dotnet, using arcgis 10.  My kind fellow ESRI forum participants have guided me thus far in constructing the procedure below.  It loads a featureclass and now I want it to load a table from the same geodatabase that the featureclass came from.  I have inserted a message box to indicate where the procedure fails. It doesn't like the last line in the try catch construct. The error message is "Object reference not set to an instance of an object". Any suggestions are appreciated.
thanks
tlh

Private Sub LoadInundationLayers()
        Dim pMxDoc As IMxDocument = DirectCast(m_app.document, IMxDocument)
        Dim pMap As IMap = pMxDoc.FocusMap
        Dim pFLayer As ESRI.ArcGIS.Carto.IFeatureLayer = New FeatureLayer
       
        Dim pWSFactory As ESRI.ArcGIS.Geodatabase.IWorkspaceFactory = New FileGDBWorkspaceFactory
        Dim pFWS As ESRI.ArcGIS.Geodatabase.IFeatureWorkspace
        Dim pFDSet As ESRI.ArcGIS.Geodatabase.IFeatureDataset
        Dim pFCContainer As ESRI.ArcGIS.Geodatabase.IFeatureClassContainer
        Dim pFClass As ESRI.ArcGIS.Geodatabase.IFeatureClass
        Dim tableCollection As ITableCollection = TryCast(m_app, ITableCollection)
        Dim pTable As ITable

        Dim intParcNum As Integer = 9
        Dim dblStage As Double = frmScenSet.lblStage.Text
        intInundationStage = (Int((dblStage + 0.05) * 10) * 10)
        Dim strGDBName As String = strDefaultWorkspace & "\Processed_Data\ShorelineManagementTool_" & frmScenSet.lblVertDatStage.Text & ".gdb"
        Dim strFDSetName As String = "InundationAreasParcel_" & intParcNum
        Dim strFClassName As String = "p" & intParcNum & intInundationStage & "_polygon"

        Try
            pFWS = pWSFactory.OpenFromFile(strGDBName, 0)
            pFDSet = pFWS.OpenFeatureDataset(strFDSetName)
            pFCContainer = CType(pFDSet, ESRI.ArcGIS.Geodatabase.IFeatureClassContainer)
            pFClass = pFCContainer.ClassByName(strFClassName)
            pFLayer.FeatureClass = pFClass
            pMap.AddLayer(pFLayer)
            pTable = pFWS.OpenTable("p" & intParcNum & intInundationStage & "_cf")
            MsgBox("code works to this point")
            tableCollection.AddTable(pTable)
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

Outcomes