LinqDataSourceStatusEventArgs.Result Property

Gets the object that represents the result of a data operation.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web.Extensions (in System.Web.Extensions.dll)

public Object Result { get; }

Property Value

Type: System.Object
An object that contains the data from the data operation.

You use the Result property to examine values returned from a data operation. You can retrieve output parameters from a data operation or modify the values returned from a query.

The data stored in the Result property depends on the type of data operation that has been performed. When you delete data, the Result property contains an object of the type specified in the TableName property, with the original values that were deleted from the data source. When you insert or update data, the Result property contains an object of the type specified in the TableName property, with the new values that were saved to the data source. When you select data, the Result property contains the results of the query.

If the select query involves grouping the data or selecting a subset of properties from the type specified in the TableName property, the Result property contains an object of a dynamically created type. Otherwise, the Result property contains an object of the type specified in the TableName property.

The following example shows an event handler for the Inserted event. In 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. The exception message is logged if the Exception property is not equal to null. The 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;            
    }
}

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft