Export (0) Print
Expand All

ObjectDataSource.Update Method

Performs an update operation by calling the method that is identified by the UpdateMethod property and any parameters that are in the UpdateParameters collection.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

member Update : unit -> int

Return Value

Type: System.Int32
A value that represents the number of rows updated in the underlying data storage.

The business object is assumed to update data one record at a time, rather than in a batch.

Before the Update operation is performed, the OnUpdating method is called to raise the Updating event. You can handle the Updating event to examine the values of the parameters and to perform any preprocessing before an Update operation. To perform an update operation, the ObjectDataSourceView object uses reflection to create an instance of the object that is identified by the TypeName property. It then calls the method that is identified by the UpdateMethod property, using any associated UpdateParameters properties. After the Update operation completes, the OnUpdated method is called to raise the Updated event. You can handle the Updated event to examine any return values, output parameters, and exceptions, and to perform any post-processing.

The Update method delegates to the Update method of the ObjectDataSourceView that is associated with the ObjectDataSource control.

For more information about parameter merging, object lifetime, and method resolution, see UpdateMethod.

Security noteSecurity Note

You should validate any parameter value that you receive from the client. The runtime simply substitutes the parameter value into the UpdateMethod property.

Data-Bound Controls

When the ObjectDataSource control is associated with a data-bound control, such as the GridView control, it is not necessary to call the Update method from page code. The Update method is invoked directly by the data-bound control instead.

This section contains two code examples. The first code example demonstrates how to use a DropDownList control, TextBox controls, and several ObjectDataSource objects to update data. The second code example shows the EmployeeLogic class that is used in the first code example.

The following code example demonstrates how to use a DropDownList control, TextBox controls, and several ObjectDataSource controls to update data. The DropDownList displays the name of a Northwind employee, while the TextBox controls are used to enter and update address information. Because the UpdateParameters collection contains a ControlParameter object that is bound to the selected value of the DropDownList, the button that raises the Update operation is enabled only after an employee is selected.

Security noteSecurity Note

This example has a text box that accepts user input, which is a potential security threat. By default, ASP.NET Web pages validate that user input does not include script or HTML elements. For more information, see Script Exploits Overview.

No code example is currently available or this language may not be supported.

The following code example shows the EmployeeLogic class that is used in the preceding code example.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft