Hello
I'm new to vb and dotnet. I'm running arcgis 10. I think I am close but need help finishing my procedure below. The code below works up to the point where I have the message box. The error I get is "Unable to cast COM object of type 'System.__ComObject" to interface type 'ESRI.ArcGIS.Carto.IFeatureLayer'" I've tried several variations on the last few lines but can't figure it out. I'm inexperienced in casting, which I think is what I need to do here. Any help is appreciated. I just want to add the featureclass that is inside the geodatabase featuredataset to the map document.
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
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 intParcNum As Integer = 9
intInundationStage = 413000
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)
MsgBox("code works up to here")
pFLayer = pFClass
pMap.AddLayer(pFLayer)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub