Quantcast
Channel: Forums - Geodatabase & ArcSDE
Viewing all articles
Browse latest Browse all 1584

Add rows to SDE table

$
0
0
I need to add records to the related table . The table is added to ArcMap. The folowing code is to add table rows for the selected features.

The VBA code works for Personal geodatabase but not for SDE table. Anyboday know why?

Code:

Private Sub TXUnit_Click()
Dim pDoc As IMxDocument
Dim pMap As IMap
Dim pFlayer As IFeatureLayer
Set pDoc = ThisDocument

Dim pTc As ITableCollection
Set pTc = pDoc.FocusMap
Dim pTable As ITable

Dim pDs As IDataset
For i = 0 To pTc.TableCount - 1
 Set pTable = pTc.Table(i)

 Set pDs = pTable

  If pDs.Name = "TransformerUnit_a" Then
  Exit For
 End If
 
Next i
Set pMap = pDoc.FocusMap
For intLoop = 0 To pMap.LayerCount - 1
   
      If pMap.Layer(intLoop).Name = "TX" Then
        Set pFlayer = pMap.Layer(intLoop)
        MsgBox pFlayer.Name
        Exit For
      End If
Next intLoop

Dim pFclass As IFeatureClass
  Set pFclass = pFlayer.FeatureClass
  Dim pFields As IFields
  Set pFields = pFclass.Fields
 
  Dim objectID As Long
  Dim FacilityID As String
  Dim RatedKVA As Double
  Dim Phase As Long
  objectID = pFields.FindField("OBJECTID")
  FacilityID = pFields.FindField("FACILITYID")
  RatedKVA = pFields.FindField("RATEDKVA")
  Phase = pFields.FindField("PHASEDESIGNATION")
 
 
  Dim pFeatureFcursor As IFeatureCursor
  Set pFeatureFcursor = pFclass.Update(Nothing, True)
  Dim pFeatureSelection As IFeatureSelection
  Dim pSelectionSet As ISelectionSet
  Set pFeatureSelection = pFlayer
  Set pSelectionSet = pFeatureSelection.SelectionSet
  pSelectionSet.Search Nothing, False, pFeatureFcursor
  Dim pFeature As IFeature
  Set pFeature = pFeatureFcursor.NextFeature
 
    Dim pTableCursor As ICursor
    Set pTableCursor = pTable.Insert(True)
   
    'add  new rows to the cursor
 
    Dim pRowBuffer As IRowBuffer
   

    Do Until pFeature Is Nothing
        Set pRowBuffer = pTable.CreateRowBuffer
   
      pRowBuffer.Value(pRowBuffer.Fields.FindField("TRANSFORMEROBJECTID")) = pFeature.Value(objectID)
      pRowBuffer.Value(pRowBuffer.Fields.FindField("FACILITYID")) = pFeature.Value(FacilityID)
      pRowBuffer.Value(pRowBuffer.Fields.FindField("RatedKVA")) = pFeature.Value(RatedKVA)
      pRowBuffer.Value(pRowBuffer.Fields.FindField("PHASEDESIGNATION")) = pFeature.Value(Phase)
   
        'insert the rowbuffer to the cursor
        pTableCursor.InsertRow pRowBuffer
 
    'flush the cursor. The records are actually stored to the data source during this operation
    pTableCursor.Flush
    Set pFeature = pFeatureFcursor.NextFeature
 Loop
 
End Sub


Viewing all articles
Browse latest Browse all 1584

Trending Articles