LinqDataSourceStatusEventArgs.Result 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得代表資料操作結果的物件。
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 物件取得產品 ID。 產品 ID 是資料表的主鍵,由資料庫設定,因此在插入操作完成前,該值不會被知道。 若 Exception 該性質不等 null於 ,則該異常訊息會被記錄。 此時屬性 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 會包含查詢的結果。
如果 select 查詢涉及將資料分組或從屬性指定 TableName 型別中選擇屬性子集,則該 Result 屬性包含一個動態產生型別的物件。 否則,屬性 Result 包含屬性中 TableName 指定的物件。