EntityDataSource.Inserting 事件

定義

發生於新物件保存至資料來源之前。

public:
 event EventHandler<System::Web::UI::WebControls::EntityDataSourceChangingEventArgs ^> ^ Inserting;
public event EventHandler<System.Web.UI.WebControls.EntityDataSourceChangingEventArgs> Inserting;
member this.Inserting : EventHandler<System.Web.UI.WebControls.EntityDataSourceChangingEventArgs> 
Public Custom Event Inserting As EventHandler(Of EntityDataSourceChangingEventArgs) 

事件類型

備註

事件 Inserting 會在新的 物件保存到資料來源之前引發。 事件 Inserting 可讓您修改或驗證正在新增的物件、新增不同的物件,或取消作業。 您可以從 物件的 屬性存取要加入 Entity 的物件 EntityDataSourceChangingEventArgs 。 如果提供不同的物件,使用者必須負責在 屬性中 Entity 設定正確的實體類型。

若要停止加入物件,請將 物件的 屬性 EntityDataSourceChangingEventArgs 設定 Canceltrue

如果建立新物件時發生錯誤,則會 Inserting 引發 事件,並將 Exception 物件的 屬性 EntityDataSourceChangingEventArgs 設定為傳 Exception 回的 。

當您在事件處理常式中 Inserting 處理例外狀況時,請將 ExceptionHandled 屬性設定為 true 。 這可防止再次引發例外狀況。 當您為 屬性指定 的值 falseExceptionHandled ,會 EntityDataSource 重新引發例外狀況。

適用於