Move FeatureClass to FeatureDataset

970
1
04-28-2011 04:19 AM
Highlighted
New Contributor III
I am creating a Network and as part of it I have to create a featuredataset called NETWORK and then I have to move an existing FeatureClass into the NETWORK featuredataset.

The code I am trying to use is:

Private Sub moveToDataset(ByVal sName As String, ByVal sToDatasetName As String, ByRef sError As String)
        ' Move a featureclass to be "within" a feature dataset
Using pComReleaser As New ESRI.ArcGIS.ADF.ComReleaser
  Dim pDatasetContainer As IDatasetContainer
        Dim pFeatureDataset As IFeatureDataset
        Dim pdataset As IFeatureDataset

Try
sError = ""

    pFC = g_pFNetWorkspace.OpenFeatureClass(sName)
    pComReleaser.ManageLifetime(pFC)

   ' Get the dataset
    pdataset = g_pFNetWorkspace.OpenFeatureDataset(sToDatasetName)

    pFeatureDataset = pFC.FeatureDataset
    pComReleaser.ManageLifetime(pFeatureDataset)

    pDatasetContainer = pdataset
    pComReleaser.ManageLifetime(pDatasetContainer)

    pDatasetContainer.AddDataset(pFeatureDataset)

   Catch ex As Exception
      sError = "ERROR: moveToDataset; Line: " & Erl() & vbCrLf & ex.Message
End Try
End Using
End Sub

The problem I keep getting is "Attempted to write protected memory" when the AddDataset line
is processed.

The Feature dataset has been created beforehand using the Spatial Reference of the featureclass
I am trying to move into it. Might that be a problem?

Am I going about this the right way? I can copy the featureclass (row-by-row) into the feature dataset so nothing appears to be wrong with it.

Thanks,

J
Reply
0 Kudos
1 Reply
Highlighted
New Contributor III
I've fixed it now and the process was quite a bit simpler than I expected:

Private Sub moveToDataset(ByVal sName As String, ByVal sToDatasetName As String, ByRef sError As String)
' Move a featureclass to be "within" a feature dataset
Using pComReleaser As New ESRI.ArcGIS.ADF.ComReleaser
Dim pDatasetContainer As IDatasetContainer
Dim pFeatureDataset As IFeatureDataset
Dim pFC As IFeatureClass

Try
sError = ""

pFeatureDataset  = g_pFNetWorkspace.OpenFeatureDataset(sToDatasetName )

' Get the FeatureClass
pFC = g_pFNetWorkspace.OpenFeatureClass(sName)

pDatasetContainer = cType(pFeatureDataset, IDatasetContainer)

pDatasetContainer.AddDataset(pFC)

Catch ex As Exception
sError = "ERROR: moveToDataset; Line: " & Erl() & vbCrLf & ex.Message
End Try
End Using
End Sub
Reply
0 Kudos