ObjectDataSource.Insert ObjectDataSource.Insert ObjectDataSource.Insert ObjectDataSource.Insert Method

定义

通过调用由 InsertMethod 属性标识的方法和 InsertParameters 集合中的所有参数,执行插入操作。Performs an insert operation by calling the method that is identified by the InsertMethod property and any parameters in the InsertParameters collection.

public:
 int Insert();
public int Insert ();
member this.Insert : unit -> int
Public Function Insert () As Integer

返回

一个表示插入到基础数据存储中的行数的值。A value that represents the number of rows inserted into the underlying data storage.

注解

在执行OnInserting操作之前, 将调用方法来引发Inserting事件。 InsertBefore the Insert operation is performed, the OnInserting method is called to raise the Inserting event. 您可以处理Inserting事件以检查参数的值并Insert在操作之前执行任何预处理。You can handle the Inserting event to examine the values of the parameters and to perform any preprocessing before an Insert operation. 若要执行插入操作, ObjectDataSourceView对象使用反射来创建TypeName由属性标识的对象的实例。To perform an insert operation, the ObjectDataSourceView object uses reflection to create an instance of the object that is identified by the TypeName property. 然后, 它使用任意关联InsertMethod InsertParameters的属性调用由属性标识的方法。It then calls the method that is identified by the InsertMethod property, using any associated InsertParameters properties. 操作完成后OnInserted , 调用方法来引发Inserted事件。 InsertAfter the Insert operation completes, the OnInserted method is called to raise the Inserted event. 您可以处理Inserted事件以检查任何返回值、输出参数和异常, 并执行任何后续处理。You can handle the Inserted event to examine any return values, output parameters, and exceptions, and to perform any post-processing.

方法委托ObjectDataSourceView Insert给与ObjectDataSource控件关联的的方法。 InsertThe Insert method delegates to the Insert method of the ObjectDataSourceView that is associated with the ObjectDataSource control.

有关参数合并、对象生存期和方法解析的详细信息, 请参阅InsertMethodFor more information about parameter merging, object lifetime, and method resolution, see InsertMethod.

数据绑定控件Data-Bound Controls

当对象与数据绑定控件 (如GridView控件) 关联时, Insert无需从页代码中调用方法。 ObjectDataSourceWhen the ObjectDataSource object is associated with a data-bound control, such as the GridView control, it is not necessary to call the Insert method from page code. 改为直接通过数据绑定控件调用方法。InsertThe Insert method is invoked directly by the data-bound control instead.

适用于

另请参阅