Using Geoprocessor to add fields

1996
2
05-26-2010 09:55 AM
LuisPenedo
New Contributor
I'm trying to add fields ussing this code:                 
                    GeoProcessor GP = new GeoProcessor();
                    GP.AddToolbox("C:/ArcGIS/ArcToolbox/Toolboxes/Data Management Tools.tbx");
                    GP.SetEnvironmentValue("workspece", pWorkSpace.PathName.ToString());           // 1
                    // Generate the array of parameters.
                    IVariantArray parameters = new VarArrayClass();

                    for (int f = 0; f < newFields.Count; f++)
                    {
                        parameters.RemoveAll();
                        parameters.Add(@"D:\SaltLakeCity_Sts.shp");

                        string fieldName = "FIELD_" + f;
                        parameters.Add(fieldName);
                        parameters.Add("TEXT");

                       
                        GP.Execute("AddField_management", parameters, null);    //  2
                    }

I was getting this error after executing or attempting to execute line //   2


Error HRESULT E_FAIL has been returned from a call to a COM component.  ESRI.ARCGIS.Geoprocessing

when adding line //  1 to try to solve the problem, I got the same error message when the program tried to execute line //  1

Any ideas?  I have not used the geoprocessor with arcobjects before (this is the first time). 

Thanks in advance for any help.

Luis F. Penedo
0 Kudos
2 Replies
LuisPenedo
New Contributor
I corrected a typo but still getting the same error after attempting to update using GP.Execute

                    GeoProcessor GP = new GeoProcessor();
                    GP.AddToolbox("C:/ArcGIS/ArcToolbox/Toolboxes/Data Management Tools.tbx");
                    GP.SetEnvironmentValue("workspace", pWorkSpace.PathName.ToString());
                    // Generate the array of parameters.
                    IVariantArray parameters = new VarArrayClass();

                    for (int f = 0; f < newFields.Count; f++)
                    {
                        //layerTable.AddField(newFields);
                        parameters.RemoveAll();
                        parameters.Add("SaltLakeCity_Sts.shp");

                        string fieldName = "FIELD_" + f;
                        parameters.Add(fieldName);
                        parameters.Add("TEXT");

                       
                        GP.Execute("AddField_management", parameters,null);
                    }
0 Kudos
ThavitinaiduGulivindala
Occasional Contributor
Relace "AddField_management" with "AddField" in the following line

GP.Execute("AddField_management", parameters,null);

Cheers,
Thaviti
0 Kudos