AnsweredAssumed Answered

How To - Update a Value in a Table

Question asked by jameskennedy2265 on Jul 12, 2019
Latest reply on Jul 23, 2019 by jameskennedy2265

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.

Outcomes