AnsweredAssumed Answered

get all the values of particular field

Question asked by abab123 on Dec 23, 2014
Latest reply on Dec 18, 2015 by Hornbydd

Hello, I want to develop a tool using Arc objects to get all the values of particular field. below is code but i am getting an error as null reference. Can anyone help me how to solve this.

public override void OnClick()

        {

 

            IMxDocument pmx = m_application.Document as IMxDocument;

            IMap pmap = pmx.FocusMap;

 

            //ILayer player = pmap.get_Layer(0);

 

            IFeatureLayer pflayer = pmap.get_Layer(0) as IFeatureLayer;

 

            IFeatureClass fc = pflayer.FeatureClass;

            IFields pfield = fc as IFields;

            ITable ptable = fc as ITable;

            ICursor pcursor = ptable.Search(null, false);

            int fldindex = fc.Fields.FindField("NAME");

            IRow prow = pcursor.NextRow();

 

            if (prow != null)

            {

 

                string output = " ";

                for (int i = 0; i <= pfield.FieldCount - 1; i++)

                {

 

                    output += pfield.get_Field(i).Name + ": " + prow.get_Value(i).ToString() + " \n";

                    MessageBox.Show(output);

                    prow = pcursor.NextRow();

                }

 

            }

                                              

        }

Outcomes