LinqDataSourceValidationException LinqDataSourceValidationException LinqDataSourceValidationException LinqDataSourceValidationException Class

定義

說明在 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
繼承
LinqDataSourceValidationExceptionLinqDataSourceValidationExceptionLinqDataSourceValidationExceptionLinqDataSourceValidationException
屬性
實作

範例

下列範例顯示的事件處理常式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.

您通常會處理中的例外狀況UpdatingDeleting,和Inserting事件。You typically handle exceptions in the Updating, Deleting, and Inserting events. 如果擲回驗證例外狀況,Exception的屬性LinqDataSourceUpdateEventArgsLinqDataSourceDeleteEventArgs,或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.

若要處理驗證例外狀況,建立的處理常式UpdatingDeleting,或Inserting事件。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. 如果Exception屬性不是 null,所擲回一或多個驗證例外狀況,您可以擷取在每個驗證例外狀況InnerExceptions屬性。If 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() LinqDataSourceValidationException() LinqDataSourceValidationException()

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

LinqDataSourceValidationException(SerializationInfo, StreamingContext) LinqDataSourceValidationException(SerializationInfo, StreamingContext) LinqDataSourceValidationException(SerializationInfo, StreamingContext) LinqDataSourceValidationException(SerializationInfo, StreamingContext)

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

LinqDataSourceValidationException(String) LinqDataSourceValidationException(String) LinqDataSourceValidationException(String) LinqDataSourceValidationException(String)

使用指定的錯誤說明訊息,初始化 LinqDataSourceValidationException 類別的新執行個體。Initializes a new instance of the LinqDataSourceValidationException class with a specified message that describes the error.

LinqDataSourceValidationException(String, Exception) LinqDataSourceValidationException(String, Exception) LinqDataSourceValidationException(String, Exception) 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(String, IDictionary<String,Exception>) LinqDataSourceValidationException(String, IDictionary<String,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 Data Data Data

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

(Inherited from Exception)
HelpLink HelpLink HelpLink HelpLink

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

(Inherited from Exception)
HResult HResult HResult HResult

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

(Inherited from Exception)
InnerException InnerException InnerException InnerException

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

(Inherited from Exception)
InnerExceptions InnerExceptions InnerExceptions InnerExceptions

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

Message Message Message Message

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

(Inherited from Exception)
Source Source Source Source

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

(Inherited from Exception)
StackTrace StackTrace StackTrace StackTrace

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

(Inherited from Exception)
TargetSite TargetSite TargetSite TargetSite

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

(Inherited from Exception)

方法

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

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

(Inherited from Object)
GetBaseException() GetBaseException() GetBaseException() GetBaseException()

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

(Inherited from Exception)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

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

(Inherited from Object)
GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext)

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

GetType() GetType() GetType() GetType()

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

(Inherited from Exception)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

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

(Inherited from Exception)

事件

SerializeObjectState SerializeObjectState SerializeObjectState SerializeObjectState

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

(Inherited from Exception)

適用於