Using Geoprocessor to add fields

Discussion created by lfpenedo on May 26, 2010
Latest reply on May 27, 2010 by thaviti
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++)

                        string fieldName = "FIELD_" + f;

                        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