通过


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 对象中检索产品 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 类型的对象。

适用于