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
type LinqDataSourceValidationException = class
    inherit Exception
    interface IDynamicValidatorException
    interface ISerializable
Public Class LinqDataSourceValidationException
Inherits Exception
Implements IDynamicValidatorException
繼承
LinqDataSourceValidationException
屬性
實作

範例

下列範例會顯示Updating事件的事件處理常式。The following example shows an event handler for the Updating event. 它會使用Label控制項來顯示任何驗證例外狀況訊息。It 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. 您可以逐一查看InnerExceptions集合, 以取得每個驗證例外狀況。You can retrieve each validation exception by iterating through the InnerExceptions collection.

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

若要處理驗證例外狀況, 請建立UpdatingDeletingInserting事件的處理常式。To 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. 如果屬性不是 null, 則會擲回一或多個驗證例外狀況, 而您可以InnerExceptions在屬性中抓取每個驗證例外狀況。 ExceptionIf 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 的淺層複本 (Shallow Copy)。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)

適用於