Share via


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 属性包含查询的结果。

如果选择查询涉及对数据进行分组或从 属性中指定的 TableName 类型中选择属性的子集,则 Result 属性包含动态创建类型的 对象。 否则, Result 属性包含 属性中指定的 TableName 类型的 对象。

适用于