Move FeatureClass to FeatureDataset

Discussion created by navjohn on Apr 28, 2011
Latest reply on May 11, 2011 by navjohn
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

sError = ""

    pFC = g_pFNetWorkspace.OpenFeatureClass(sName)

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

    pFeatureDataset = pFC.FeatureDataset

    pDatasetContainer = pdataset


   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.