LinqDataSourceStatusEventArgs 类

定义

ContextCreatedDeletedInsertedSelectedUpdated 事件提供数据。Provides data for the ContextCreated, Deleted, Inserted, Selected, and Updated events.

public ref class LinqDataSourceStatusEventArgs : EventArgs
public class LinqDataSourceStatusEventArgs : EventArgs
type LinqDataSourceStatusEventArgs = class
    inherit EventArgs
Public Class LinqDataSourceStatusEventArgs
Inherits EventArgs
继承
LinqDataSourceStatusEventArgs

示例

下面的示例演示Inserted事件的事件处理程序。The following example shows an event handler for the Inserted event. 在事件处理程序中, 如果Exception属性为null, 则Result从属性中的对象检索产品 ID。In the event handler, if the Exception property is null, the product ID is retrieved from the object in the Result property. Product ID 是表的主键, 由数据库进行设置, 因此, 在完成插入操作之前值是未知的。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. 如果该Exception属性不null等于, 则记录异常消息。The exception message is logged if the Exception property is not equal to null. true然后将ExceptionHandled属性设置为。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;            
    }
}
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

注解

利用类, 您可以检查LinqDataSource由控件执行的数据操作的结果。 LinqDataSourceStatusEventArgsThe LinqDataSourceStatusEventArgs class enables you to examine the results of data operations that have been performed by a LinqDataSource control. ContextCreated对象传递Deleted给控件LinqDataSource的、Inserted 、、Updated和事件的事件处理程序。 Selected LinqDataSourceStatusEventArgsA LinqDataSourceStatusEventArgs object is passed to event handlers for the ContextCreated, Deleted, Inserted, Selected, and Updated events of the LinqDataSource control.

如果数据操作成功完成, 则生成的数据对象存储在Result属性中Exception , 属性为nullIf the data operation completed successfully, the resulting data object is stored in the Result property and the Exception property is null. 如果数据操作失败, 则在数据操作过程中发生的异常将存储在Exception属性中, Result而属性为nullIf the data operation failed, the exception that occurred during the data operation is stored in the Exception property and the Result property is null. 如果处理了由Exception属性表示的异常, 则ExceptionHandled将属性设置为true , 以便不会引发异常。If you handled the exception represented by the Exception property, set the ExceptionHandled property to true so that the exception will not be thrown.

您可以通过TotalRowCount属性检索查询返回的数据记录总数。You retrieve the total number of data records returned from a query through the TotalRowCount property.

构造函数

LinqDataSourceStatusEventArgs(Exception)

使用数据操作所引发的异常初始化 LinqDataSourceStatusEventArgs 类的新实例。Initializes a new instance of the LinqDataSourceStatusEventArgs class by using an exception that occurred as a result of the data operation.

LinqDataSourceStatusEventArgs(Object)

使用包含数据操作结果数据的对象初始化 LinqDataSourceStatusEventArgs 类的新实例。Initializes a new instance of the LinqDataSourceStatusEventArgs class by using an object that contains the data from the data operation.

LinqDataSourceStatusEventArgs(Object, Int32)

使用包含数据操作结果数据以及返回的行数的对象初始化 LinqDataSourceStatusEventArgs 类的新实例。Initializes a new instance of the LinqDataSourceStatusEventArgs class with an object that contains the data from the data operation and the number of rows returned.

属性

Exception

获取在数据操作过程中引发的异常。Gets the exception that was thrown during the data operation.

ExceptionHandled

获取或设置一个值,该值指示异常是否已得到处理而不该再次引发。Gets or sets a value that indicates whether the exception was handled and that it should not be thrown again.

Result

获取表示数据操作结果的对象。Gets the object that represents the result of a data operation.

TotalRowCount

获取数据检索操作过程中在某个数据集中检索的总行数。Gets the total number of rows in a data set from a data-retrieval operation.

方法

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
ToString()

返回一个表示当前对象的 string。Returns a string that represents the current object.

(继承自 Object)

适用于