LinqDataSourceValidationException 類別

定義

說明在 LinqDataSource 控制項插入、更新或刪除值之前,在驗證新值或修改值期間所發生的例外狀況。Describes an exception that occurred during validation of new or modified values before values are inserted, updated, or deleted by a LinqDataSource control.

public ref class LinqDataSourceValidationException : Exception, System::Web::DynamicData::IDynamicValidatorException
[System.Serializable]
public class LinqDataSourceValidationException : Exception, System.Web.DynamicData.IDynamicValidatorException
[<System.Serializable>]
type LinqDataSourceValidationException = class
    inherit Exception
    interface IDynamicValidatorException
    interface ISerializable
Public Class LinqDataSourceValidationException
Inherits Exception
Implements IDynamicValidatorException
繼承
LinqDataSourceValidationException
屬性
實作

範例

下列範例顯示事件的事件處理常式 UpdatingThe following example shows an event handler for the Updating event. 它會使用控制項來顯示任何驗證例外狀況訊息 LabelIt displays any validation exception messages by using a Label control.

Protected Sub LinqDataSource_Updating(ByVal sender As Object, _  
        ByVal e As LinqDataSourceUpdateEventArgs)  
    If (e.Exception IsNot Nothing) Then  
        For Each innerException As KeyValuePair(Of String, Exception) _  
               In e.Exception.InnerExceptions  
            Label1.Text &= innerException.Key & ": " & _  
                innerException.Value.Message & "<br />"  
        Next  
        e.ExceptionHandled = True  
    End If  
End Sub  
protected void LinqDataSource_Updating(object sender,   
        LinqDataSourceUpdateEventArgs e)  
{  
    if (e.Exception != null)  
    {  
        foreach (KeyValuePair<string, Exception> innerException in   
             e.Exception.InnerExceptions)  
        {  
        Label1.Text += innerException.Key + ": " +   
            innerException.Value.Message + "<br />";  
        }  
        e.ExceptionHandled = true;  
    }  
}  

備註

LinqDataSourceValidationException類別包含型別轉換和屬性 setter 例外狀況。The LinqDataSourceValidationException class contains type conversion and property setter exceptions. 在驗證期間擲回的所有例外狀況都會包含在 InnerExceptions 集合中。All of the exceptions that are thrown during validation are contained in the InnerExceptions collection. 您可以逐一查看集合,以取得每個驗證例外狀況 InnerExceptionsYou can retrieve each validation exception by iterating through the InnerExceptions collection.

您通常會處理 Updating 、和事件中的例外狀況 Deleting InsertingYou typically handle exceptions in the Updating, Deleting, and Inserting events. 如果擲回驗證例外狀況,則 Exception LinqDataSourceUpdateEventArgs 、或物件的屬性會 LinqDataSourceDeleteEventArgs LinqDataSourceInsertEventArgs 包含 LinqDataSourceValidationException 物件。If a validation exception is thrown, the Exception property of the LinqDataSourceUpdateEventArgs, LinqDataSourceDeleteEventArgs, or LinqDataSourceInsertEventArgs object contains a LinqDataSourceValidationException object. 如果未擲回例外狀況, Exception 屬性會包含 nullIf no exception is thrown, the Exception property contains null.

若要處理驗證例外狀況,請建立 Updating 、或事件的處理常式 Deleting InsertingTo handle validation exceptions, create a handler for the Updating, Deleting, or Inserting event. 在事件處理常式中,檢查 Exception 事件引數類別的屬性是否包含以外的值 nullIn the event handler, check whether the Exception property of the event argument class contains a value other than null. 如果 Exception 屬性不是 null,則會擲回一個或多個驗證例外狀況,而且您可以在屬性中取出每個驗證例外狀況 InnerExceptionsIf the Exception property is not null, one or more validation exceptions were thrown and you can retrieve each validation exception in the InnerExceptions property.

如果值不符合屬性的類型,就會發生驗證例外狀況。A validation exception can occur if a value does not match the type of the property. 例如,嘗試使用非數位字元來更新整數屬性會導致驗證例外狀況。For example, trying to update an integer property by using non-numeric characters causes a validation exception. LINQ to SQL 類別也可以包含自訂的驗證準則,以確定屬性包含的值在預期的範圍或模式中。A LINQ to SQL class can also contain customized validation criteria that make sure that the property contains a value that is within an expected range or pattern.

建構函式

LinqDataSourceValidationException()

使用系統提供的錯誤描述訊息,初始化 LinqDataSourceValidationException 類別的新執行個體。Initializes a new instance of the LinqDataSourceValidationException class with a system-supplied message that describes the error.

LinqDataSourceValidationException(SerializationInfo, StreamingContext)

使用序列化資料,初始化 LinqDataSourceValidationException 類別的新執行個體。Initializes a new instance of the LinqDataSourceValidationException class with serialized data.

LinqDataSourceValidationException(String)

初始化具有指定的錯誤描述訊息之 LinqDataSourceValidationException 類別的新執行個體。Initializes a new instance of the LinqDataSourceValidationException class with a specified message that describes the error.

LinqDataSourceValidationException(String, Exception)

初始化具有指定的錯誤訊息和內部例外狀況參考之 LinqDataSourceValidationException 類別的新執行個體。Initializes a new instance of the LinqDataSourceValidationException class with a specified error message and a reference to the inner exception.

LinqDataSourceValidationException(String, IDictionary<String,Exception>)

使用指定的錯誤說明訊息和內部例外狀況的參考集合,初始化 LinqDataSourceValidationException 類別的新執行個體。Initializes a new instance of the LinqDataSourceValidationException class with a specified message that describes the error, and a collection of references to inner exceptions.

屬性

Data

取得鍵值組的集合,這些鍵值組會提供關於例外狀況的其他使用者定義資訊。Gets a collection of key/value pairs that provide additional user-defined information about the exception.

(繼承來源 Exception)
HelpLink

取得或設定與這個例外狀況相關聯的說明檔連結。Gets or sets a link to the help file associated with this exception.

(繼承來源 Exception)
HResult

取得或設定 HRESULT,它是指派給特定例外狀況的編碼數值。Gets or sets HRESULT, a coded numerical value that is assigned to a specific exception.

(繼承來源 Exception)
InnerException

取得造成目前例外狀況的 Exception 執行個體。Gets the Exception instance that caused the current exception.

(繼承來源 Exception)
InnerExceptions

取得在驗證新的或修改的資料時所發生的一個或多個例外狀況。Gets one or more exceptions that occurred when new or modified data was being validated.

Message

取得描述目前例外狀況的訊息。Gets a message that describes the current exception.

(繼承來源 Exception)
Source

取得或設定造成錯誤的應用程式或物件的名稱。Gets or sets the name of the application or the object that causes the error.

(繼承來源 Exception)
StackTrace

取得呼叫堆疊上即時運算框架的字串表示。Gets a string representation of the immediate frames on the call stack.

(繼承來源 Exception)
TargetSite

取得擲回目前例外狀況的方法。Gets the method that throws the current exception.

(繼承來源 Exception)

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)
GetBaseException()

在衍生類別中覆寫時,傳回一或多個後續的例外狀況的根本原因 ExceptionWhen overridden in a derived class, returns the Exception that is the root cause of one or more subsequent exceptions.

(繼承來源 Exception)
GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(繼承來源 Object)
GetObjectData(SerializationInfo, StreamingContext)

取得例外狀況的相關資訊,並將此資訊加入至 SerializationInfo 物件。Gets information about the exception and adds it to the SerializationInfo object.

GetType()

取得目前執行個體的執行階段類型。Gets the runtime type of the current instance.

(繼承來源 Exception)
MemberwiseClone()

建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(繼承來源 Object)
ToString()

建立並傳回目前例外狀況的字串表示。Creates and returns a string representation of the current exception.

(繼承來源 Exception)

事件

SerializeObjectState

當例外狀況序列化,以建立包含例外狀況相關序列化資料的例外狀況狀態物件時,就會發生此事件。Occurs when an exception is serialized to create an exception state object that contains serialized data about the exception.

(繼承來源 Exception)

適用於