UPDATE

UPDATE is used to update columns of existing rows in a given list with new values.

Syntax

UPDATE
list_name [.content_type_name]
SET col_name = expr [, col_name = expr ...]
[WHERE where_condition];

The UPDATE statement is used as follows:

  1. The list_name indicates the list to update rows in. Optionally, you can also specify the content type, in which case only rows of the given content type will be updated.
  2. The SET clause indicates which columns to modify and the values they should be given. The usage is similar to that of the INSERT statement.
  3. The WHERE clause, if given, specifies the conditions that are used to identify the rows to update. The where_condition evaluates true for all rows to be updated. With no WHERE clause all rows in the list are updated. See Operators And Functions for detailed examples of WHERE usage and available operators.

    Example: to update rows in the list Employees where Role column is not Salesman:

    UPDATE Employees SET Active = True WHERE Role <> 'Salesman';

    The DefaultLimit option in the connection string places a default limit on the number of rows that can be updated.

  4. When the procedure returns, the application can obtain the number of rows affected through the LastRecordsAffected property of the SharePointCommand class.

Code examples

Update customers without country

using (var connection = new SharePointConnection(connectionString))
{
    connection.Open();
    using (var command = new SharePointCommand(@"Update Customers SET Country = 'Unknown' WHERE Country IS NULL", connection))
    {
        command.ExecuteNonQuery();
        Console.WriteLine("Affected rows = " + command.LastRecordsAffected);
    }
}

Code result

Affected rows = 1

Set all customers as active

using (var connection = new SharePointConnection(connectionString))
{
    connection.Open();
    using (var command = new SharePointCommand(@"Update Customers SET Active = True", connection))
    {
        command.ExecuteNonQuery();
        Console.WriteLine("Affected rows = " + command.LastRecordsAffected);
    }
}

Code result

Affected rows = 13


Skip Navigation Links.

Visa     MasterCard