I have a form that allows users to update attribute information for selected features...but I'm recieving the error: "Exception from HRESULT: 0x80041051" when it tries to update the data. I'm using VB.net, Visual Studio Express 2008 and ArcGIS 10.

Any suggestions on where I went wrong with updating the data?

System.Runtime.InteropServices.COMException was caught
  Message="Exception from HRESULT: 0x80041051"
       at ESRI.ArcGIS.Geodatabase.IFeatureCursor.UpdateFeature(IFeature Object)
       at ImprovementProjectsLines.ImprovementLines.cmdUpdate_Click(Object sender,     EventArgs e)


     Private Sub cmdUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdUpdate.Click
     Dim pMxDoc As IMxDocument
        pMxDoc = My.ArcMap.Document
        Dim pMap As IMap
        pMap = pMxDoc.FocusMap
        'Dim pFLayer As IFeatureSelection

        'Get a reference to the editor.
        Dim editor As IEditor
        editor = My.ArcMap.Application.FindExtensionByName("esriEditor.Editor")

        'Get Crossings FeatureLayer
        Dim pFeatLyr As IFeatureLayer
        pFeatLyr = GetLayerByTOC("TransportationImprovementProjects_Lines")

        'Get Dataset from FeatureLayer
        Dim pEditDataset As IDataset
        pEditDataset = pFeatLyr

        'If not editing, start editing dataset's Workspace
        If editor.EditState <> esriEditState.esriStateEditing Then
        End If

        'Get SelectionSet
        Dim pSelSet As ISelectionSet
        pSelSet = GetSelection(pFeatLyr)

        'Get FeatureCursor from SelectionSet
        Dim pFCursor As IFeatureCursor = Nothing
        pSelSet.Search(Nothing, False, pFCursor)

        'Initialize first (only) feature
        Dim pFeat As IFeature
        pFeat = pFCursor.NextFeature

        'Update attributes with user input
        'Fill in Attributes of selected feature in User Form
        Do Until pFeat Is Nothing
            pFeat.Value(pFeat.Fields.FindField("YEAR")) = txtPrjYear.Text
            pFeat.Value(pFeat.Fields.FindField("PROJECTYPE")) = txtPrjType.Text
            pFeat.Value(pFeat.Fields.FindField("LOCATION")) = txtLocation.Text
            pFeat.Value(pFeat.Fields.FindField("AGENCY")) = txtAgency.Text
            pFeat.Value(pFeat.Fields.FindField("DESCRIPTION")) = txtDescrip.Text
            pFeat.Value(pFeat.Fields.FindField("COST")) = txtCost.Text
            pFeat.Value(pFeat.Fields.FindField("DATEEDITED")) = txtDate.Text
            pFeat.Value(pFeat.Fields.FindField("USEREDITED")) = txtUser.Text

            pFeat = pFCursor.NextFeature

        'Stop editing and save edits

        'Close form

    Catch ex As Exception
        Windows.Forms.MessageBox.Show(ex.ToString, "error")

    End Try
End Sub

Public Function GetSelection(ByVal pFeatLyr As IFeatureLayer) As ISelectionSet

    'Gets selection of feature layer and returns selection set

    'Initialize the required variables
    pMxDoc = My.ArcMap.Application.Document
    Dim pFeatSel As IFeatureSelection
    pFeatSel = pFeatLyr

    GetSelection = pFeatSel.SelectionSet

End Function

Public Function GetLayerByTOC(ByVal lyrName As String) As IFeatureLayer

    'This function finds a feature layer based on its TOC Name

    'Initalize global variables
    pMxDoc = My.ArcMap.Application.Document
    Dim pMap As IMap
    pMap = pMxDoc.FocusMap

    Dim lyrCntr As Integer
    Dim pFeatLyr As IFeatureLayer

    For lyrCntr = 0 To pMap.LayerCount - 1

        'Ensure that the layer is valid
        If pMap.Layer(lyrCntr).Valid = True Then

            'Ensure that the layer is a feature layer
            If TypeOf pMap.Layer(lyrCntr) Is IFeatureLayer Then
                pFeatLyr = pMap.Layer(lyrCntr)

                If UCase(pMap.Layer(lyrCntr).Name) = UCase(lyrName) Then
                    GetLayerByTOC = pFeatLyr
                    Exit Function
                End If
            End If
        End If
    Next lyrCntr

    Return Nothing
    'Layer not found. Show a message
    MsgBox("Layer " & lyrName & " not found !", vbCritical, "Error")

End Function

End Class


HRESULT: 0x80041051 is FDO_E_CURSOR_WRONG_TYPE. Change:

pSelSet.Search(Nothing, True, pFCursor)


pSelSet.Search(Nothing, False, pFCursor)

and see what happens.

  • Chase, thanks for the reply...I get a "null reference to pfCursor"..so I added "dim pfCursor as IFeatureCursor=Nothing" and I still receive that error. I updated the code above. – user5373 Jan 9 '12 at 16:20
  • Don't have your environment - can't debug your code - you need to ensure that all those variables you are setting in that code are actually being set and/or are valid when entering that code. (Does GetSelection() return a valid ISelectionSet? (You need to find out.)) – Chaz Jan 9 '12 at 17:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.