DataTable.GetChanges Método
Definição
Obtém uma cópia do DataTable que contém todas as alterações feitas nele desde que foi carregado pela última vez ou desde que AcceptChanges() foi chamado.Gets a copy of the DataTable containing all changes made to it since it was last loaded, or since AcceptChanges() was called.
Sobrecargas
| GetChanges() |
Obtém uma cópia do DataTable que contém todas as alterações feitas nele desde que ele foi carregado ou que o AcceptChanges() foi chamado pela última vez.Gets a copy of the DataTable that contains all changes made to it since it was loaded or AcceptChanges() was last called. |
| GetChanges(DataRowState) |
Obtém uma cópia do DataTable que contém todas as alterações feitas desde o último carregamento ou desde que AcceptChanges() foi chamado, filtrado por DataRowState.Gets a copy of the DataTable containing all changes made to it since it was last loaded, or since AcceptChanges() was called, filtered by DataRowState. |
GetChanges()
Obtém uma cópia do DataTable que contém todas as alterações feitas nele desde que ele foi carregado ou que o AcceptChanges() foi chamado pela última vez.Gets a copy of the DataTable that contains all changes made to it since it was loaded or AcceptChanges() was last called.
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
Retornos
Uma cópia das alterações neste DataTable ou null se nenhuma alteração foi encontrada.A copy of the changes from this DataTable, or null if no changes are found.
Exemplos
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
Comentários
Cria um novo DataSet contendo uma cópia de todas as linhas no original DataSet que têm alterações pendentes.Creates a new DataSet containing a copy of all rows in the original DataSet that have pending changes. As restrições de relação podem fazer com que linhas adicionais não alteradas sejam adicionadas ao novo DataSet se as linhas inalteradas contiverem chaves primárias correspondentes às chaves estrangeiras nas linhas alteradas.Relationship constraints can cause additional unchanged rows to be added to the new DataSet if the unchanged rows contain primary keys corresponding to foreign keys in the changed rows. O método retorna null ( Nothing em Visual Basic) se não houver nenhuma linha no original DataSet com alterações pendentes.The method returns null (Nothing in Visual Basic) if there are no rows in the original DataSet with pending changes.
Aplica-se a
GetChanges(DataRowState)
Obtém uma cópia do DataTable que contém todas as alterações feitas desde o último carregamento ou desde que AcceptChanges() foi chamado, filtrado por DataRowState.Gets a copy of the DataTable containing all changes made to it since it was last loaded, or since AcceptChanges() was called, filtered by 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
Parâmetros
- rowStates
- DataRowState
Um dos valores de DataRowState.One of the DataRowState values.
Retornos
Uma cópia filtrada do DataTable que pode ter ações executadas nela e, mais tarde, ser mesclada novamente ao DataTable usando Merge(DataSet).A filtered copy of the DataTable that can have actions performed on it, and later be merged back in the DataTable using Merge(DataSet). Se nenhuma linha do DataRowState desejado for encontrada, o método retornará null.If no rows of the desired DataRowState are found, the method returns null.
Exemplos
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
Comentários
O GetChanges método é usado para produzir um segundo DataTable objeto que contém apenas as alterações introduzidas no original.The GetChanges method is used to produce a second DataTable object that contains only the changes introduced into the original. Use o rowStates argumento para especificar o tipo de alterações que o novo objeto deve incluir.Use the rowStates argument to specify the type of changes the new object should include.
As restrições de relação podem fazer com que linhas pai inalteradas sejam incluídas.Relationship constraints may cause unchanged parent rows to be included.