Adding feature to Pro feature class in hosted service

448
1
09-01-2020 11:58 AM
by Anonymous User
Not applicable

HI, I am trying to add create a feature using the rowbuffer and create row functions in c#. I am using the following code to attempt creating the polyline.  

using (geodb)
{
using (FeatureClass fc = geodb.OpenDataset<FeatureClass>("6"))
{

RowBuffer rowBuffer = fc.CreateRowBuffer();

rowBuffer["SHAPE"] = poly;

Feature feat= fc.CreateRow(rowBuffer);
fc.Dispose();

}
geodb.Dispose();
}

I receive the error 

A geodatabase exception has occurred.

on the fc.createrow

0 Kudos
1 Reply
RichRuh
Esri Regular Contributor

Hi Jordan,

Is there any error message with the exception?

Generally in an ArcGIS Pro add-in it's better to use the Editor.  This adds your edit to the operation stack for undo/redo and refreshes the map.  An example of creating a feature using the Editor can be found here.

If you do want to use the low-level editing routines, perhaps because this is a CoreHost application, you should adjust your use of Dispose/using and add a transaction as follows:

using (Geodatabase geodb = ObtainGeodatabaseWithCodeYouDidntShow())
{
  geodb.ApplyEdits(()=> 
  {
    using (FeatureClass fc = geodb.OpenDataset<FeatureClass>("6"))
    using (RowBuffer rowBuffer = fc.CreateRowBuffer();
    {
      rowBuffer["SHAPE"] = poly;
      fc.CreateRow(rowBuffer).Dispose();  //disposes the row created by CreateRow
    } // using block disposes fc and rowBuffer
  });
} // using block disposes geodb

I hope this helps.

--Rich

0 Kudos