LinqDataSourceStatusEventArgs 類別

定義

提供 ContextCreatedDeletedInsertedSelected 以及 Updated 事件的資料。Provides data for the ContextCreated, Deleted, Inserted, Selected, and Updated events.

public ref class LinqDataSourceStatusEventArgs : EventArgs
public class LinqDataSourceStatusEventArgs : EventArgs
type LinqDataSourceStatusEventArgs = class
    inherit EventArgs
Public Class LinqDataSourceStatusEventArgs
Inherits EventArgs
繼承
LinqDataSourceStatusEventArgs

範例

下列範例顯示事件的事件處理常式 InsertedThe following example shows an event handler for the Inserted event. 在事件處理常式中,如果 Exception 屬性為 null ,則會從屬性中的物件取出產品識別碼 ResultIn the event handler, if the Exception property is null, the product ID is retrieved from the object in the Result property. 產品識別碼是資料表的主鍵,而且是由資料庫所設定,因此在插入作業完成之前,不會知道此值。The product ID is a primary key for the table and is set by the database, therefore the value is not known until the insert operation has finished. 如果屬性不等於,則會記錄例外狀況訊息 Exception nullThe exception message is logged if the Exception property is not equal to null. ExceptionHandled然後,屬性會設定為 trueThe ExceptionHandled property is then set to true.

protected void LinqDataSource_Inserted(object sender, LinqDataSourceStatusEventArgs e)
{
    if (e.Exception == null)
    {
        Product newProduct = (Product)e.Result;
        Literal1.Text = "The new product id is " + newProduct.ProductID;
        Literal1.Visible = true;            
    }
    else
    {
        LogError(e.Exception.Message);
        Literal1.Text = "We are sorry. There was a problem saving the record. The administrator has been notified.";
        Literal1.Visible = true;
        e.ExceptionHandled = true;            
    }
}
Protected Sub LinqDataSource_Inserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.LinqDataSourceStatusEventArgs)
    If (IsNothing(e.Exception)) Then
        Dim newProduct As Product
        newProduct = CType(e.Result, Product)
        Literal1.Text = "The new product id is " & newProduct.ProductID
        Literal1.Visible = True
    Else
        LogError(e.Exception.Message)
        Literal1.Text = "We are sorry. There was a problem saving the record. The administrator has been notified."
        Literal1.Visible = True
        e.ExceptionHandled = True
    End If
End Sub

備註

LinqDataSourceStatusEventArgs類別可讓您檢查控制項所執行的資料作業結果 LinqDataSourceThe LinqDataSourceStatusEventArgs class enables you to examine the results of data operations that have been performed by a LinqDataSource control. LinqDataSourceStatusEventArgs物件會傳遞至 ContextCreated 控制項的、、 Deleted InsertedSelectedUpdated 事件 LinqDataSource 的事件處理常式。A LinqDataSourceStatusEventArgs object is passed to event handlers for the ContextCreated, Deleted, Inserted, Selected, and Updated events of the LinqDataSource control.

如果資料作業順利完成,則產生的資料物件會儲存在屬性中, ResultException 屬性為 nullIf the data operation completed successfully, the resulting data object is stored in the Result property and the Exception property is null. 如果資料作業失敗,則在資料作業期間發生的例外狀況會儲存在屬性中, ExceptionResult 屬性為 nullIf the data operation failed, the exception that occurred during the data operation is stored in the Exception property and the Result property is null. 如果您已處理由屬性工作表示的例外狀況 Exception ,請將屬性設定為,如此就不會擲回 ExceptionHandled true 例外狀況。If you handled the exception represented by the Exception property, set the ExceptionHandled property to true so that the exception will not be thrown.

您可以透過屬性來取得查詢所傳回的資料記錄總數 TotalRowCountYou retrieve the total number of data records returned from a query through the TotalRowCount property.

建構函式

LinqDataSourceStatusEventArgs(Exception)

使用因為資料作業而發生的例外狀況,初始化 LinqDataSourceStatusEventArgs 類別的新執行個體。Initializes a new instance of the LinqDataSourceStatusEventArgs class by using an exception that occurred as a result of the data operation.

LinqDataSourceStatusEventArgs(Object)

使用包含資料作業所產生資料的物件,初始化 LinqDataSourceStatusEventArgs 類別的新執行個體。Initializes a new instance of the LinqDataSourceStatusEventArgs class by using an object that contains the data from the data operation.

LinqDataSourceStatusEventArgs(Object, Int32)

使用包含資料作業所產生資料和所傳回資料列數的物件,初始化 LinqDataSourceStatusEventArgs 類別的新執行個體。Initializes a new instance of the LinqDataSourceStatusEventArgs class with an object that contains the data from the data operation and the number of rows returned.

屬性

Exception

取得在資料作業期間擲回的例外狀況。Gets the exception that was thrown during the data operation.

ExceptionHandled

取得或設定值,這個值表示是否處理了例外狀況以及是否不應再度擲回此例外狀況。Gets or sets a value that indicates whether the exception was handled and that it should not be thrown again.

Result

取得表示資料作業結果的物件。Gets the object that represents the result of a data operation.

TotalRowCount

取得資料擷取作業中資料集的資料列總數。Gets the total number of rows in a data set from a data-retrieval operation.

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(繼承來源 Object)
GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)

適用於