DB2®ResultSet.Update Method

Send the pending updates for the current record to the underlying row on the database server.

Namespace:
IBM.Data.DB2
Assembly:
IBM.Data.DB2 (in IBM.Data.DB2.dll)

Syntax


[Visual Basic]
Public Sub Update
[C#]
public void Update ()
[C++]
public:
void Update ()
[JScript]
public function Update ()

Exceptions

Exception type Condition
InvalidOperationException An updatable cursor is required.
InvalidOperationException No data exists for the row/column. The DB2ResulSet cursor is not positioned on a record.
InvalidOperationException An update is being attempted on a row that has been deleted.

Remarks

Your application must explicitly call the DB2ResultSet.Update method when updating a record's column values, or the changes to the column values will be lost when the cursor moves to a different row.

Example

[C#] The following example demonstrates how to update a row from a DB2ResultSet instance, provided the server supports updatable cursors.

[C#]
  public static void updateSalesData(DB2Connection conn)
  {
    string salesQuery = "SELECT * FROM SALES";
    DB2Command cmd = new DB2Command(salesQuery, conn);
    DB2ResultSet salesRS = cmd.ExecuteResultSet(
      DB2ResultSetOptions.Scrollable |
      DB2ResultSetOptions.Sensitive |
      DB2ResultSetOptions.SkipDeleted |
      DB2ResultSetOptions.Updatable);

    if (salesRS.ReadLast())
    {
      if (salesRS.Updatable)
      {
        salesRS.SetDB2Date(0, new DB2Date(DateTime.Now));
        salesRS.SetDB2String(1, new DB2String("Erik"));
        salesRS.SetDB2String(2, new DB2String("Ontario-South"));
        salesRS.SetDB2Int32(3, new DB2Int32(2));

        salesRS.Update();
      }
    }

    return;
  }