Suggérer une traduction
 
Suggestions d'autres utilisateurs :

progress indicator
Aucune autre suggestion.
Cliquez pour évaluer et commenter
MSDN
MSDN Library
Développement .NET
.NET Framework 4
Espaces de noms System.Web
System.Web.UI.WebControls
Réduire tout/Développer tout Réduire tout
Affichage du contenu :  côte à côteAffichage du contenu : côte à côte
.NET Framework Class Library
LinqDataSourceValidationException Class

Describes an exception that occurred during validation of new or modified values before values are inserted, updated, or deleted by a LinqDataSource control.

System..::.Object
  System..::.Exception
    System.Web.UI.WebControls..::.LinqDataSourceValidationException

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web.Extensions (in System.Web.Extensions.dll)
Visual Basic
<SerializableAttribute> _
Public Class LinqDataSourceValidationException _
    Inherits Exception _
    Implements IDynamicValidatorException, ISerializable
C#
[SerializableAttribute]
public class LinqDataSourceValidationException : Exception, 
    IDynamicValidatorException, ISerializable
Visual C++
[SerializableAttribute]
public ref class LinqDataSourceValidationException : public Exception, 
    IDynamicValidatorException, ISerializable
F#
[<SerializableAttribute>]
type LinqDataSourceValidationException =  
    class
        inherit Exception
        interface IDynamicValidatorException
        interface ISerializable
    end

The LinqDataSourceValidationException type exposes the following members.

  NameDescription
Public methodLinqDataSourceValidationException()()()Initializes a new instance of the LinqDataSourceValidationException class with a system-supplied message that describes the error.
Public methodLinqDataSourceValidationException(String)Initializes a new instance of the LinqDataSourceValidationException class with a specified message that describes the error.
Protected methodLinqDataSourceValidationException(SerializationInfo, StreamingContext)Initializes a new instance of the LinqDataSourceValidationException class with serialized data.
Public methodLinqDataSourceValidationException(String, IDictionary<(Of <(String, Exception>)>))Initializes a new instance of the LinqDataSourceValidationException class with a specified message that describes the error, and a collection of references to inner exceptions.
Public methodLinqDataSourceValidationException(String, Exception)Initializes a new instance of the LinqDataSourceValidationException class with a specified error message and a reference to the inner exception.
Top
  NameDescription
Public propertyDataGets a collection of key/value pairs that provide additional user-defined information about the exception. (Inherited from Exception.)
Public propertyHelpLinkGets or sets a link to the help file associated with this exception. (Inherited from Exception.)
Protected propertyHResultGets or sets HRESULT, a coded numerical value that is assigned to a specific exception. (Inherited from Exception.)
Public propertyInnerExceptionGets the Exception instance that caused the current exception. (Inherited from Exception.)
Public propertyInnerExceptionsGets one or more exceptions that occurred when new or modified data was being validated.
Public propertyMessageGets a message that describes the current exception. (Inherited from Exception.)
Public propertySourceGets or sets the name of the application or the object that causes the error. (Inherited from Exception.)
Public propertyStackTraceGets a string representation of the immediate frames on the call stack. (Inherited from Exception.)
Public propertyTargetSiteGets the method that throws the current exception. (Inherited from Exception.)
Top
  NameDescription
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetBaseExceptionWhen overridden in a derived class, returns the Exception that is the root cause of one or more subsequent exceptions. (Inherited from Exception.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetObjectDataGets information about the exception and adds it to the SerializationInfo object. (Overrides Exception..::.GetObjectData(SerializationInfo, StreamingContext).)
Public methodGetTypeGets the runtime type of the current instance. (Inherited from Exception.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringCreates and returns a string representation of the current exception. (Inherited from Exception.)
Top
  NameDescription
Protected eventSerializeObjectStateOccurs when an exception is serialized to create an exception state object that contains serialized data about the exception. (Inherited from Exception.)
Top

The LinqDataSourceValidationException class contains type conversion and property setter exceptions. All of the exceptions that are thrown during validation are contained in the InnerExceptions collection. You can retrieve each validation exception by iterating through the InnerExceptions collection.

You typically handle exceptions in the Updating, Deleting, and Inserting events. If a validation exception is thrown, the Exception property of the LinqDataSourceUpdateEventArgs, LinqDataSourceDeleteEventArgs, or LinqDataSourceInsertEventArgs object contains a LinqDataSourceValidationException object. If no exception is thrown, the Exception property contains nullNothingnullptra null reference (Nothing in Visual Basic).

To handle validation exceptions, create a handler for the Updating, Deleting, or Inserting event. In the event handler, check whether the Exception property of the event argument class contains a value other than nullNothingnullptra null reference (Nothing in Visual Basic). 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. 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.

The following example shows an event handler for the Updating event. It displays any validation exception messages by using a Label control.

Visual Basic
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

[C#]

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;
    }
}

.NET Framework

Supported in: 4, 3.5

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role not supported), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Bibliothèque de classes .NET Framework
LinqDataSourceValidationException, classe

Décrit une exception qui s'est produite durant la validation de valeurs nouvelles ou modifiées avant que des valeurs ne soient insérées, mises à jour ou supprimées par un contrôle LinqDataSource.

System..::.Object
  System..::.Exception
    System.Web.UI.WebControls..::.LinqDataSourceValidationException

Espace de noms :  System.Web.UI.WebControls
Assembly :  System.Web.Extensions (dans System.Web.Extensions.dll)
Visual Basic
<SerializableAttribute> _
Public Class LinqDataSourceValidationException _
    Inherits Exception _
    Implements IDynamicValidatorException, ISerializable
C#
[SerializableAttribute]
public class LinqDataSourceValidationException : Exception, 
    IDynamicValidatorException, ISerializable
VisualC++
[SerializableAttribute]
public ref class LinqDataSourceValidationException : public Exception, 
    IDynamicValidatorException, ISerializable
F#
[<SerializableAttribute>]
type LinqDataSourceValidationException =  
    class
        inherit Exception
        interface IDynamicValidatorException
        interface ISerializable
    end

Le type LinqDataSourceValidationException expose les membres suivants.

  NomDescription
Méthode publiqueLinqDataSourceValidationException()()()Initialise une nouvelle instance de la classe LinqDataSourceValidationException avec un message système qui décrit l'erreur.
Méthode publiqueLinqDataSourceValidationException(String)Initialise une nouvelle instance de la classe LinqDataSourceValidationException avec un message spécifié décrivant l'erreur.
Méthode protégéeLinqDataSourceValidationException(SerializationInfo, StreamingContext)Initialise une nouvelle instance de la classe LinqDataSourceValidationException avec des données sérialisées.
Méthode publiqueLinqDataSourceValidationException(String, IDictionary<(Of <(String, Exception>)>))Initialise une nouvelle instance de la classe LinqDataSourceValidationException avec un message spécifié décrivant l'erreur et une collection de références aux exceptions internes.
Méthode publiqueLinqDataSourceValidationException(String, Exception)Initialise une nouvelle instance de la classe LinqDataSourceValidationException avec un message d'erreur spécifié et une référence à l'exception interne.
Début
  NomDescription
Propriété publiqueDataObtient une collection de paires clé/valeur qui fournissent des informations supplémentaires définies par l'utilisateur sur l'exception. (Hérité de Exception.)
Propriété publiqueHelpLinkObtient ou définit un lien vers le fichier d'aide associé à cette exception. (Hérité de Exception.)
Propriété protégéeHResultObtient ou définit HRESULT, valeur numérique codée qui est assignée à une exception spécifique. (Hérité de Exception.)
Propriété publiqueInnerExceptionObtient l'instance Exception qui a provoqué l'exception actuelle. (Hérité de Exception.)
Propriété publiqueInnerExceptionsObtient une ou plusieurs exceptions qui se sont produites lors de la validation de données nouvelles ou modifiées.
Propriété publiqueMessageObtient un message qui décrit l'exception actuelle. (Hérité de Exception.)
Propriété publiqueSourceObtient ou définit le nom de l'application ou de l'objet qui est à l'origine de l'erreur. (Hérité de Exception.)
Propriété publiqueStackTraceObtient une représentation sous forme de chaîne des frames immédiates sur la pile des appels. (Hérité de Exception.)
Propriété publiqueTargetSiteObtient la méthode qui lève l'exception actuelle. (Hérité de Exception.)
Début
  NomDescription
Méthode publiqueEquals(Object)Détermine si l'Object spécifié est égal à l'Object en cours. (Hérité de Object.)
Méthode protégéeFinalizeAutorise un objet à tenter de libérer des ressources et d'exécuter d'autres opérations de netto***ge avant qu'il ne soit récupéré par l'opération garbage collection. (Hérité de Object.)
Méthode publiqueGetBaseExceptionEn cas de substitution dans une classe dérivée, retourne Exception qui est à l'origine d'une ou de plusieurs exceptions suivantes. (Hérité de Exception.)
Méthode publiqueGetHashCodeSert de fonction de hachage pour un type particulier. (Hérité de Object.)
Méthode publiqueGetObjectDataObtient des informations sur l'exception et les ajoute à l'objet SerializationInfo. (Substitue Exception..::.GetObjectData(SerializationInfo, StreamingContext).)
Méthode publiqueGetTypeObtient le type au moment de l'exécution de l'instance actuelle. (Hérité de Exception.)
Méthode protégéeMemberwiseCloneCrée une copie superficielle de l'objet Object actif. (Hérité de Object.)
Méthode publiqueToStringCrée et retourne une chaîne représentant l'exception en cours. (Hérité de Exception.)
Début
  NomDescription
Événement protégéSerializeObjectStateSe produit lorsqu'une exception est sérialisée pour créer un objet d'état d'exception qui contient des données sérialisées relatives à l'exception. (Hérité de Exception.)
Début

La classe LinqDataSourceValidationException contient la conversion de type et des exceptions d'accesseur Set de propriété. Toutes les exceptions levées pendant la validation sont contenues dans la collection InnerExceptions. Vous pouvez extraire chaque exception de validation en itérant au sein de la collection InnerExceptions.

Vous gérez en général des exceptions dans l' Updating, Deleting et les événements Inserting. Si une exception de validation est levée, la propriété Exception du LinqDataSourceUpdateEventArgs, LinqDataSourceDeleteEventArgs, ou l'objet LinqDataSourceInsertEventArgs contient un objet LinqDataSourceValidationException. Si aucune exception n'est levée, la propriété Exception contient nullNothingnullptrune référence null (Nothing en Visual Basic).

Pour gérer des exceptions de validation, créez un gestionnaire pour Updating, Deleting ou l'événement Inserting. Dans le gestionnaire d'événements, vérifiez si la propriété Exception de la classe d'arguments d'événements contient une valeur autre que nullNothingnullptrune référence null (Nothing en Visual Basic). Si la propriété Exception n'est pas nulle, une ou plusieurs exceptions de validation ont été levées et vous pouvez extraire chacune d'entre elles dans la propriété InnerExceptions.

Une exception de validation peut se produire si une valeur ne correspond pas au type de la propriété. Par exemple, la tentative de mise à jour d'une propriété d'entier à l'aide de caractères non numériques provoque une exception de validation. Une classe LINQ to SQL peut également contenir des critères de validation personnalisés qui s'assurent que la propriété contient une valeur figurant dans une plage ou un modèle prévu.

L'exemple suivant montre un gestionnaire d'événements pour l'événement Updating. Il affiche tous les messages d'exception de validation à l'aide d'un contrôle Label.

Visual Basic
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

[C#]

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;
    }
}

.NET Framework

Pris en charge dans : 4, 3.5

Windows 7, Windows Vista SP1 ou ultérieur, Windows XP SP3, Windows Server 2008 (installation minimale non prise en charge), Windows Server 2008 R2 (installation minimale prise en charge avec SP1 ou version ultérieure), Windows Server 2003 SP2

Le .NET Framework ne prend pas en charge toutes les versions de chaque plateforme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise du .NET Framework.
Tous les membres static (Shared en Visual Basic) publics de ce type sont thread-safe. Il n'est pas garanti que les membres d'instance soient thread-safe.
Contenu de la communauté   Qu'est-ce que le Contenu de la communauté ?
Ajouter du contenu RSS  Annotations
Processing
© 2012 Microsoft. Tous droits réservés. Conditions d'utilisation | Marques | Confidentialité
Page view tracker