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.
Assembly: System.Web (in System.Web.dll)
Return Value
Type: System::Int32A 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 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 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. |
The following code example shows the EmployeeLogic class that is used in the preceding code example.
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Security Note