ObjectDataSource.Insert 方法

定义

通过调用由 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

返回

Int32

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

注解

Insert 执行操作之前,将 OnInserting 调用方法来引发 Inserting 事件。Before the Insert operation is performed, the OnInserting method is called to raise the Inserting event. 您可以处理 Inserting 事件以检查参数的值并在操作之前执行任何预处理 InsertYou can handle the Inserting event to examine the values of the parameters and to perform any preprocessing before an Insert operation. 若要执行插入操作, ObjectDataSourceView 对象使用反射来创建由属性标识的对象的实例 TypeNameTo perform an insert operation, the ObjectDataSourceView object uses reflection to create an instance of the object that is identified by the TypeName property. 然后 InsertMethod ,它使用任意关联的属性调用由属性标识的方法 InsertParametersIt then calls the method that is identified by the InsertMethod property, using any associated InsertParameters properties. Insert操作完成后, OnInserted 调用方法来引发 Inserted 事件。After 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.

Insert方法委托给 Insert ObjectDataSourceView 与控件关联的的方法 ObjectDataSourceThe 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

ObjectDataSource 对象与数据绑定控件(如控件)关联时, GridView 无需 Insert 从页代码中调用方法。When 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. Insert改为直接通过数据绑定控件调用方法。The Insert method is invoked directly by the data-bound control instead.

适用于

另请参阅