DataTable.GetChanges Metodo

Definizione

Ottiene una copia dell'oggetto DataTable contenente tutte le modifiche apportate sin dall'ultimo caricamento o dall'ultima chiamata a AcceptChanges().

Overload

GetChanges()

Ottiene una copia della classe DataTable contenente tutte le modifiche apportate a essa dal momento in cui è stata caricata o dall'ultima chiamata al metodo AcceptChanges().

GetChanges(DataRowState)

Ottiene una copia della classe DataTable contenente tutte le modifiche apportate a essa dal momento in cui è stata caricata o dall'ultima chiamata al metodo AcceptChanges(), filtrata dall'enumerazione DataRowState.

GetChanges()

Ottiene una copia della classe DataTable contenente tutte le modifiche apportate a essa dal momento in cui è stata caricata o dall'ultima chiamata al metodo AcceptChanges().

public:
 System::Data::DataTable ^ GetChanges();
public System.Data.DataTable? GetChanges ();
public System.Data.DataTable GetChanges ();
member this.GetChanges : unit -> System.Data.DataTable
Public Function GetChanges () As DataTable

Restituisce

DataTable

Copia delle modifiche di questo oggetto DataTable , oppure null se non vengono rilevate modifiche.

Esempio

private void UpdateDataTable(DataTable table,
    OleDbDataAdapter myDataAdapter)
{
    DataTable xDataTable = table.GetChanges();

    // Check the DataTable for errors.
    if (xDataTable.HasErrors)
    {
        // Insert code to resolve errors.
    }

    // After fixing errors, update the database with the DataAdapter
    myDataAdapter.Update(xDataTable);
}
Private Sub UpdateDataTable(table As DataTable, _
    myDataAdapter As OleDbDataAdapter)

    Dim xDataTable As DataTable = table.GetChanges()

    ' Check the DataTable for errors.
    If xDataTable.HasErrors Then
        ' Insert code to resolve errors.
    End If

    ' After fixing errors, update the database with the DataAdapter 
    myDataAdapter.Update(xDataTable)
End Sub

Commenti

Crea un nuovo DataSet contenente una copia di tutte le righe nell'originale che hanno modifiche in sospeso DataSet . I vincoli di relazione possono causare l'aggiunta di righe invariate aggiuntive al nuovo DataSet se le righe non modificate contengono chiavi primarie corrispondenti alle chiavi esterne nelle righe modificate. Il metodo restituisce null (Nothing in Visual Basic) se non sono presenti righe nell'originale con modifiche in sospesoDataSet.

Vedi anche

Si applica a

GetChanges(DataRowState)

Ottiene una copia della classe DataTable contenente tutte le modifiche apportate a essa dal momento in cui è stata caricata o dall'ultima chiamata al metodo AcceptChanges(), filtrata dall'enumerazione DataRowState.

public:
 System::Data::DataTable ^ GetChanges(System::Data::DataRowState rowStates);
public System.Data.DataTable? GetChanges (System.Data.DataRowState rowStates);
public System.Data.DataTable GetChanges (System.Data.DataRowState rowStates);
member this.GetChanges : System.Data.DataRowState -> System.Data.DataTable
Public Function GetChanges (rowStates As DataRowState) As DataTable

Parametri

rowStates
DataRowState

Uno dei valori di DataRowState.

Restituisce

DataTable

Copia filtrata della classe DataTable su cui è possibile eseguire azioni e che successivamente può essere unita di nuovo nella classe DataTable utilizzando il metodo Merge(DataSet). Se non viene trovata alcuna riga dell'oggetto DataRowState desiderato, questo metodo restituirà null.

Esempio

private void ProcessDeletes(DataTable table,
    OleDbDataAdapter adapter)
{
    DataTable changeTable = table.GetChanges(DataRowState.Deleted);

    // Check the DataTable for errors.
    if (changeTable.HasErrors)
    {
        // Insert code to resolve errors.
    }

    // After fixing errors, update the database with the DataAdapter
    adapter.Update(changeTable);
}
Private Sub ProcessDeletes(table As DataTable, _
    adapter As OleDbDataAdapter)

   Dim changeTable As DataTable = table.GetChanges(DataRowState.Deleted)

   ' Check the DataTable for errors.
   If table.HasErrors Then
      ' Insert code to resolve errors.
   End If

   ' After fixing errors, update the database with the DataAdapter 
   adapter.Update(changeTable)
End Sub

Commenti

Il GetChanges metodo viene usato per produrre un secondo DataTable oggetto che contiene solo le modifiche introdotte nell'originale. Usare l'argomento rowStates per specificare il tipo di modifiche che deve includere il nuovo oggetto.

I vincoli di relazione possono causare l'inserimento di righe padre invariate.

Vedi anche

Si applica a