ArcGIS Pro 3.3 API Reference Guide
ArcGIS.Core.Data Namespace / Table Class / CreateRowBuffer Method / CreateRowBuffer(Row) Method
The template row used to create the RowBuffer.
Example

In This Topic
    CreateRowBuffer(Row) Method
    In This Topic
    Creates a new row buffer instance in memory. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    public RowBuffer CreateRowBuffer( 
       Row row
    )
    Public Overloads Function CreateRowBuffer( _
       ByVal row As Row _
    ) As RowBuffer

    Parameters

    row
    The template row used to create the RowBuffer.

    Return Value

    A RowBuffer used to set the field values when calling CreateRow.
    Exceptions
    ExceptionDescription
    The template row must belong to this table.
    A geodatabase-related exception has occurred.
    Remarks

    No row is created in the database.

    The returned RowBuffer does not have an object ID value.

    Example
    Creating a Row
    public async Task CreatingARow()
    {
      string message = String.Empty;
      bool creationResult = false;
      EditOperation editOperation = new EditOperation();
    
      await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
      {
    
        using (Geodatabase geodatabase = new Geodatabase(
          new DatabaseConnectionFile(new Uri("path\\to\\sde\\file\\sdefile.sde"))))
        using (Table enterpriseTable = geodatabase.OpenDataset<Table>("LocalGovernment.GDB.piCIPCost"))
        {
    
          //var geodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(uri)) for a File GDB
          //
          //var shapeFileConnPath = new FileSystemConnectionPath(uri, FileSystemDatastoreType.Shapefile);
          //var shapefile = new FileSystemDatastore(shapeFileConnPath);
          //var table = shapefile.OpenDataset<Table>(strShapeFileName); for a Shape file
    
          //declare the callback here. We are not executing it .yet.
          editOperation.Callback(context =>
          {
            TableDefinition tableDefinition = enterpriseTable.GetDefinition();
            int assetNameIndex = tableDefinition.FindField("ASSETNA");
    
            using (RowBuffer rowBuffer = enterpriseTable.CreateRowBuffer())
            {
              // Either the field index or the field name can be used in the indexer.
              rowBuffer[assetNameIndex] = "wMain";
              rowBuffer["COST"] = 700;
              rowBuffer["ACTION"] = "Open Cut";
    
              // subtype value for "Abandon".
              rowBuffer[tableDefinition.GetSubtypeField()] = 3;
    
              using (Row row = enterpriseTable.CreateRow(rowBuffer))
              {
                // To Indicate that the attribute table has to be updated.
                context.Invalidate(row);
              }
            }
          }, enterpriseTable);
    
          try
          {
            creationResult = editOperation.Execute();
            if (!creationResult) message = editOperation.ErrorMessage;
          }
          catch (GeodatabaseException exObj)
          {
            message = exObj.Message;
          }
        }
      });
    
      if (!string.IsNullOrEmpty(message))
        MessageBox.Show(message);
    
    }
    Creating a Feature
    public async Task CreatingAFeature()
    {
      string message = String.Empty;
      bool creationResult = false;
    
      await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
      {
        using (Geodatabase geodatabase = new Geodatabase(new DatabaseConnectionFile(new Uri("path\\to\\sde\\file\\sdefile.sde"))))
        using (FeatureClass enterpriseFeatureClass = geodatabase.OpenDataset<FeatureClass>("LocalGovernment.GDB.FacilitySite"))
        {
          //var geodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(uri)) for a File GDB
          //
          //var shapeFileConnPath = new FileSystemConnectionPath(uri, FileSystemDatastoreType.Shapefile);
          //var shapefile = new FileSystemDatastore(shapeFileConnPath);
          //var table = shapefile.OpenDataset<Table>(strShapeFileName); for a Shape file
    
          //declare the callback here. We are not executing it yet
          EditOperation editOperation = new EditOperation();
          editOperation.Callback(context =>
          {
            FeatureClassDefinition facilitySiteDefinition = enterpriseFeatureClass.GetDefinition();
            int facilityIdIndex = facilitySiteDefinition.FindField("FACILITYID");
    
            using (RowBuffer rowBuffer = enterpriseFeatureClass.CreateRowBuffer())
            {
              // Either the field index or the field name can be used in the indexer.
              rowBuffer[facilityIdIndex] = "wMain";
              rowBuffer["NAME"] = "Griffith Park";
              rowBuffer["OWNTYPE"] = "Municipal";
              rowBuffer["FCODE"] = "Park";
              // Add it to Public Attractions Subtype.
              rowBuffer[facilitySiteDefinition.GetSubtypeField()] = 820;
    
              List<Coordinate2D> newCoordinates = new List<Coordinate2D>
              {
                  new Coordinate2D(1021570, 1880583),
                  new Coordinate2D(1028730, 1880994),
                  new Coordinate2D(1029718, 1875644),
                  new Coordinate2D(1021405, 1875397)
                };
    
              rowBuffer[facilitySiteDefinition.GetShapeField()] = new PolygonBuilderEx(newCoordinates).ToGeometry();
    
              using (Feature feature = enterpriseFeatureClass.CreateRow(rowBuffer))
              {
                //To Indicate that the attribute table has to be updated
                context.Invalidate(feature);
              }
            }
    
          }, enterpriseFeatureClass);
    
          try
          {
            creationResult = editOperation.Execute();
            if (!creationResult) message = editOperation.ErrorMessage;
          }
          catch (GeodatabaseException exObj)
          {
            message = exObj.Message;
          }
        }
      });
    
      if (!string.IsNullOrEmpty(message))
        MessageBox.Show(message);
    }
    Writing a Blob field
    public async Task WriteBlobField(Table table, string blobFieldName, string imageFileName)
    {
      await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
      {
        // Read the image file into a MemoryStream
        MemoryStream memoryStream = new MemoryStream(); ;
        using (FileStream imageFile = new FileStream(imageFileName, FileMode.Open, FileAccess.Read))
        {
          imageFile.CopyTo(memoryStream);
        }
    
        // Create a new row in the table, and write the Memory Stream into a blob fiele
        using (RowBuffer rowBuffer = table.CreateRowBuffer())
        {
          rowBuffer[blobFieldName] = memoryStream;
          table.CreateRow(rowBuffer).Dispose();
        }
      });
    }
    Creating a new Annotation Feature in an Annotation FeatureClass using a RowBuffer
    public async Task CreatingAnAnnotationFeature(Geodatabase geodatabase)
    {
      await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
      {
        using (AnnotationFeatureClass annotationFeatureClass = geodatabase.OpenDataset<AnnotationFeatureClass>("Annotation // feature // class // name"))
        using (AnnotationFeatureClassDefinition annotationFeatureClassDefinition = annotationFeatureClass.GetDefinition())
        using (RowBuffer rowBuffer = annotationFeatureClass.CreateRowBuffer())
        using (AnnotationFeature annotationFeature = annotationFeatureClass.CreateRow(rowBuffer))
        {
          annotationFeature.SetAnnotationClassID(0);
          annotationFeature.SetStatus(AnnotationStatus.Placed);
    
          // Get the annotation labels from the label collection
          IReadOnlyList<CIMLabelClass> labelClasses =
            annotationFeatureClassDefinition.GetLabelClassCollection();
    
          // Setup the symbol reference with the symbol id and the text symbol
          CIMSymbolReference cimSymbolReference = new CIMSymbolReference();
          cimSymbolReference.Symbol = labelClasses[0].TextSymbol.Symbol;
          cimSymbolReference.SymbolName = labelClasses[0].TextSymbol.SymbolName;
    
          // Setup the text graphic
          CIMTextGraphic cimTextGraphic = new CIMTextGraphic();
          cimTextGraphic.Text = "Charlotte, North Carolina";
          cimTextGraphic.Shape = new MapPointBuilderEx(new Coordinate2D(-80.843, 35.234), SpatialReferences.WGS84).ToGeometry();
          cimTextGraphic.Symbol = cimSymbolReference;
    
          // Set the symbol reference on the graphic and store
          annotationFeature.SetGraphic(cimTextGraphic);
          annotationFeature.Store();
        }
      });
    }
    Creating a row buffer from a template row
    public void CreateRowBufferFromARow(Table table)
    {
      using (RowCursor rowCursor = table.Search())
      {
        if (rowCursor.MoveNext())
        {
          using (Row templateRow = rowCursor.Current)
          {
            RowBuffer rowBuffer = table.CreateRowBuffer(templateRow);
    
            // Manipulate row buffer
            // Doesn't allow copying values of ObjectID and GlobalID
            //
            // rowBuffer["Field"] = "Update";
            //
    
            // create a new row
            table.CreateRow(rowBuffer);
          }
        }
      }
    }
    
    Creating a row buffer from a template row
    public void CreateRowBufferFromARow(Table table)
    {
      using (RowCursor rowCursor = table.Search())
      {
        if (rowCursor.MoveNext())
        {
          using (Row templateRow = rowCursor.Current)
          {
            RowBuffer rowBuffer = table.CreateRowBuffer(templateRow);
    
            // Manipulate row buffer
            // Doesn't allow copying values of ObjectID and GlobalID
            //
            // rowBuffer["Field"] = "Update";
            //
    
            // create a new row
            table.CreateRow(rowBuffer);
          }
        }
      }
    }
    
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3.2 or higher.
    See Also