When used in an ArcGIS Pro add-in, insert cursors should be used within an edit operation callback. For stand-alone CoreHost applications, calls to this method (and use of the insert cursor) should be enclosed within a call to Geodatabase.ApplyEdits.
// Insert Cursors are intended for use in CoreHost applications, not Pro Add-ins
publicvoid UsingInsertCursor()
{
using (Geodatabase geodatabase = new Geodatabase(new DatabaseConnectionFile(new Uri("path\\to\\sde\\file"))))
using (Table citiesTable = geodatabase.OpenDataset<Table>("name\\of\\cities_table"))
{
geodatabase.ApplyEdits(() =>
{
using (InsertCursor insertCursor = citiesTable.CreateInsertCursor())
using (RowBuffer rowBuffer = citiesTable.CreateRowBuffer())
{
rowBuffer["State"] = "Colorado";
rowBuffer["Name"] = "Fort Collins";
rowBuffer["Population"] = 167830;
insertCursor.Insert(rowBuffer);
rowBuffer["Name"] = "Denver";
rowBuffer["Population"] = 727211;
insertCursor.Insert(rowBuffer);
// Insert more rows here
// A more realistic example would be reading source data from a file
insertCursor.Flush();
}
});
}
}