KevinGebhardt86

Exception Calculating Field

Discussion created by KevinGebhardt86 on Oct 26, 2012
Latest reply on Oct 27, 2012 by rfairhur24
Hello,
I'm getting an exception HRESULT: 0x80020006 (DISP_E_UNKNOWNNAME) when i try to calculate a field in arcobjects .net.
Here is my Code:

calculateField(ref ifc, "OT_SCHLUE","dm","Dim dM As String If Len([GEMARKUNG]) > 1 Then  dm = \"14\"+[GEMARKUNG]  Else   dM = Left([GEM_SCHLUE],8) End If");
                               

private void calculateField(ref IFeatureClass featureClass, String fieldName, String expression,String condition)
        {
ICalculator calculator = new Calculator();
if (expression.Length > 0)
    calculator.Expression = expression;
if (condition.Length > 0)
    calculator.PreExpression = condition;
if (fieldName.Length > 0)
    calculator.Field = fieldName;
calculator.Cursor = (ICursor)featureClass.Update(null,true);
calculator.Calculate();
}
The variable ifc is my IFeatureClass which consists of the fields "OT_SCHLUE", "GEM_SCHLUE" and "GEMARKUNG".
I try to get the content of "GEMARKUNG" to the field "OT_SCHLUE" by calculating it.
Therefor i define an expression "dm" an a pre-expression "Dim dm As String ..."
This worked in the modelbuilder.
But now i get the message that the field is unknown, but it is part of the FeatureClass, i checked that out.

Has anyone of you an idea?

Outcomes