Condividi tramite


DataTable.HasErrors Proprietà

Definizione

Ottiene un valore che indica se sono presenti errori in una qualsiasi delle righe di una delle tabelle dell'oggetto DataSet a cui appartiene la tabella.

public:
 property bool HasErrors { bool get(); };
[System.ComponentModel.Browsable(false)]
public bool HasErrors { get; }
[System.ComponentModel.Browsable(false)]
[System.Data.DataSysDescription("DataTableHasErrorsDescr")]
public bool HasErrors { get; }
[<System.ComponentModel.Browsable(false)>]
member this.HasErrors : bool
[<System.ComponentModel.Browsable(false)>]
[<System.Data.DataSysDescription("DataTableHasErrorsDescr")>]
member this.HasErrors : bool
Public ReadOnly Property HasErrors As Boolean

Valore della proprietà

true se esistono errori; in caso contrario false, .

Attributi

Esempio

Nell'esempio seguente viene utilizzata la HasErrors proprietà per verificare se una tabella contiene errori.

private void CheckForErrors(DataSet dataSet)
{
    // Invoke GetChanges on the DataSet to create a reduced set.
    DataSet thisDataSet = dataSet.GetChanges();

    // Check each table's HasErrors property.
    foreach(DataTable table in thisDataSet.Tables)
    {
        // If HasErrors is true, reconcile errors.
        if(table.HasErrors)
        {
            // Insert code to reconcile errors.
        }
    }
}
Private Sub CheckForErrors(dataSet As DataSet)
    ' Invoke GetChanges on the DataSet to create a reduced set.
    Dim thisDataSet As DataSet = dataSet.GetChanges()

    ' Check each table's HasErrors property.
    Dim table As DataTable
    For Each table In thisDataSet.Tables
        ' If HasErrors is true, reconcile errors.
        If table.HasErrors Then
            ' Insert code to reconcile errors.
        End If
    Next table
End Sub

Commenti

Quando gli utenti lavorano su un set di dati contenuti in un DataTableoggetto , è possibile contrassegnare ogni modifica con un errore se la modifica causa un errore di convalida. È possibile contrassegnare un intero DataRow oggetto con un messaggio di errore usando la RowError proprietà . È anche possibile impostare errori in ogni colonna della riga con il SetColumnError metodo .

Prima di aggiornare un'origine dati con , DataSetè consigliabile richiamare prima il GetChanges metodo nella destinazione DataSet. Il metodo restituisce un oggetto DataSet che contiene solo le modifiche apportate all'originale. Prima di inviare l'oggetto DataSet all'origine dati per l'aggiornamento, controllare la HasErrors proprietà di ogni tabella per verificare se sono stati associati errori alle righe o alle colonne nelle righe.

Dopo aver riconciliato ogni errore, cancellare gli errori con il ClearErrors metodo di DataRow.

Si applica a

Vedi anche