Ler em inglês

Compartilhar via


DataSet.HasChanges Método

Definição

Obtém um valor que indica se o DataSet tem alterações, incluindo linhas novas, excluídas ou modificadas.

Sobrecargas

HasChanges()

Obtém um valor que indica se o DataSet tem alterações, incluindo linhas novas, excluídas ou modificadas.

HasChanges(DataRowState)

Obtém um valor que indica se o DataSet tem alterações, incluindo linhas novas, excluídas ou modificadas, filtradas por DataRowState.

HasChanges()

Origem:
DataSet.cs
Origem:
DataSet.cs
Origem:
DataSet.cs

Obtém um valor que indica se o DataSet tem alterações, incluindo linhas novas, excluídas ou modificadas.

public bool HasChanges ();

Retornos

true se o DataSet tiver alterações; caso contrário, false.

Exemplos

O exemplo a seguir usa o GetChanges método para criar um segundo DataSet objeto que, em seguida, é usado para atualizar uma fonte de dados.

private void UpdateDataSet(DataSet dataSet)
{
    // Check for changes with the HasChanges method first.
    if(!dataSet.HasChanges()) return;

    // Create temporary DataSet variable.
    DataSet tempDataSet;

    // GetChanges for modified rows only.
    tempDataSet = dataSet.GetChanges(DataRowState.Modified);

    // Check the DataSet for errors.
    if(tempDataSet.HasErrors)
    {
        // Insert code to resolve errors.
    }
    // After fixing errors, update the data source with
    // the DataAdapter used to create the DataSet.
    myOleDbDataAdapter.Update(tempDataSet);
}

Confira também

Aplica-se a

.NET 9 e outras versões
Produto Versões
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

HasChanges(DataRowState)

Origem:
DataSet.cs
Origem:
DataSet.cs
Origem:
DataSet.cs

Obtém um valor que indica se o DataSet tem alterações, incluindo linhas novas, excluídas ou modificadas, filtradas por DataRowState.

public bool HasChanges (System.Data.DataRowState rowStates);

Parâmetros

rowStates
DataRowState

Um dos valores de DataRowState.

Retornos

true se o DataSet tiver alterações; caso contrário, false.

Exemplos

O exemplo a seguir usa o GetChanges método para criar um segundo DataSet objeto, que é usado para atualizar uma fonte de dados.

private void UpdateDataSet(DataSet dataSet)
{
    // Check for changes with the HasChanges method first.
    if(!dataSet.HasChanges(DataRowState.Modified)) return;

    // Create temporary DataSet variable and
    // GetChanges for modified rows only.
    DataSet tempDataSet =
        dataSet.GetChanges(DataRowState.Modified);

    // Check the DataSet for errors.
    if(tempDataSet.HasErrors)
    {
        // Insert code to resolve errors.
    }
    // After fixing errors, update the data source with
    // the DataAdapter used to create the DataSet.
    adapter.Update(tempDataSet);
}

Comentários

Examine a HasChanges propriedade do antes de DataSet invocar o GetChanges método .

Confira também

Aplica-se a

.NET 9 e outras versões
Produto Versões
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1