How To - Update a Value in a Table

670
4
07-12-2019 10:17 AM
JamesKennedy1
New Contributor III

I would like to know how I can update a value in a table.

Here is my first go from looking at all the examples.

RowCursor cursor = profilesByStation.Search(null, false);
            string nameoftable = profilesByStation.GetName();


            int riverField = cursor.FindField(General.MMCProperties.Instance.getPropertyAsString("FieldsProfileRiverCode"));
            int reachField = cursor.FindField(General.MMCProperties.Instance.getPropertyAsString("FieldsProfileReachCode"));
            int stationField = cursor.FindField(General.MMCProperties.Instance.getPropertyAsString("FieldsProfileStation"));


            int measField = cursor.FindField(General.MMCProperties.Instance.getPropertyAsString("FieldsProfileRef"));
            string refMileField = General.MMCProperties.Instance.getPropertyAsString("FieldsXsRefMile");

            if (riverField == -1 || reachField == -1 || stationField == -1 || measField == -1) {
                System.Windows.Forms.MessageBox.Show("An error was encountered when trying to update the refmile data. The river field, reach field, station field, or measField was not found.\r\n");
                return;
            }


            while (cursor.MoveNext()) {
                Row row = cursor.Current;

                object river = row[riverField];
                object reach = row[reachField];
                object station = row[stationField];

                if (!(river is System.DBNull || reach is System.DBNull || station is System.DBNull)) {
                    Models.XSecLocate xSecLocate = Models.XSecLocate.findXSecLocate(xSecLocateList,Convert.ToString(river),Convert.ToString(reach),Convert.ToDouble(station),true);
                    if (xSecLocate != null) {
                        row[measField] = xSecLocate.Meas;
                        row[refMileField] = xSecLocate.Meas;
                    }
                }


            }

As you can see I am updating the row/column field value by 

row[refMileField] = xSecLocate.Meas;

However when I do this, it doesn't appear that anything in my table was updated.

Tags (3)
0 Kudos
4 Replies
RichRuh
Esri Regular Contributor

Hi James,

I would check out the ProConcepts Editing help topic. This snippet can probably be modified to solve your issue.

I hope this helps,

--Rich

0 Kudos
JamesKennedy1
New Contributor III

Hi Rich,

Thanks for that. I am now using the code

var modifyOp = new ArcGIS.Desktop.Editing.EditOperation();
                        modifyOp.Name = "Update Fields";
                        modifyOp.Modify(row, measField, xSecLocate.Meas);
                        //modifyOp.Modify(row, refMileField, xSecLocate.Meas);
                        modifyOp.Execute();

However it appears to be going very slow. I have a table of roughly 600,000 points. Updating each row is quite long. Is there a way to increase the speed of it? Or is there a more optimized approach to doing this?

0 Kudos
RichRuh
Esri Regular Contributor

Are you updating each row in its own EditOperation?

Or all you calling modifyOp.Modify() 600,000 times for the single call to new EditOperation()?

0 Kudos
JamesKennedy1
New Contributor III

Thanks for the advice, I'll change that so it just does it in one EditOperation.

0 Kudos