LinqDataSourceStatusEventArgs.Result 屬性

定義

取得表示資料作業結果的物件。

public:
 property System::Object ^ Result { System::Object ^ get(); };
public object Result { get; }
member this.Result : obj
Public ReadOnly Property Result As Object

屬性值

包含資料作業所產生資料的物件。

範例

下列範例顯示 事件的事件處理常式 Inserted 。 在事件處理常式中 Exception ,如果 屬性為 null ,則會從 屬性中的 Result 物件擷取產品識別碼。 產品識別碼是資料表的主鍵,而且是由資料庫設定,因此在插入作業完成之前,不會知道此值。 如果 屬性不等於 nullException 則會記錄例外狀況訊息。 屬性 ExceptionHandled 接著會設定為 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

備註

您可以使用 Result 屬性來檢查從資料作業傳回的值。 您可以從資料作業擷取輸出參數,或修改從查詢傳回的值。

儲存在 屬性中的資料 Result 取決於已執行的資料作業類型。 當您刪除資料時, Result 屬性會包含 屬性中指定的 TableName 型別物件,以及從資料來源中刪除的原始值。 當您插入或更新資料時, Result 屬性會包含 屬性中指定的 TableName 型別物件,以及儲存至資料來源的新值。 當您選取資料時, Result 屬性會包含查詢的結果。

如果選取查詢牽涉到將資料分組,或從 屬性中指定的 TableName 類型選取屬性子集,則 Result 屬性會包含動態建立類型的 物件。 否則, Result 屬性會包含 屬性中指定的 TableName 型別物件。

適用於