Repository for Ideas & Research
Open Source GIS, Hydrologic Modeling, Optimization

How to use the field calculator using ArcObjects

ICalculator calc;
ICursor cur;

calc = new CalculatorClass();
calc.Cursor = cur = ((IDisplayTable)targetLayer).SearchDisplayTable(null, false);
calc.Field = string.Format("{0}.{1}", targetLayer.Name, targetFieldName);
calc.Expression = string.Format("[{0}.{1}]", ((IDataset)sourceTable).Name, sourceFieldName);
calc.Calculate();

// release cur here
if (Marshal.IsComObject(cur ))
{
    Marshal.FinalReleaseComObject(cur );
}

// this garbage collection makes Geoprocessing tools crash
//GC.Collect();
GC.WaitForPendingFinalizers();

Wed Sep 6 07:58:35 2017 EDT by Huidae Cho
Parsing time: 0.023 seconds
XHTML . CSS . Powered by Uniqki!