DataSet.HasChanges メソッド

定義

DataSet に新しい行、削除された行、変更された行などの変更があるかどうかを示す値を取得します。

オーバーロード

HasChanges()

DataSet に新しい行、削除された行、変更された行などの変更があるかどうかを示す値を取得します。

HasChanges(DataRowState)

DataSetDataRowState でフィルター処理された新しい行、削除された行、変更された行などの変更があるかどうかを示す値を取得します。

HasChanges()

ソース:
DataSet.cs
ソース:
DataSet.cs
ソース:
DataSet.cs

DataSet に新しい行、削除された行、変更された行などの変更があるかどうかを示す値を取得します。

public:
 bool HasChanges();
public bool HasChanges ();
member this.HasChanges : unit -> bool
Public Function HasChanges () As Boolean

戻り値

DataSet に変更がある場合は true。それ以外の場合は false

次の例では、 メソッドを GetChanges 使用して 2 つ目 DataSet のオブジェクトを作成し、データ ソースの更新に使用します。

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);
}
Private Sub UpdateDataSet(ByVal dataSet As DataSet)
    ' Check for changes with the HasChanges method first.
    If Not dataSet.HasChanges() Then 
        Exit Sub
    End If

    ' Create temporary DataSet variable.
    ' GetChanges for modified rows only.
    Dim tempDataSet As DataSet = _
        dataSet.GetChanges(DataRowState.Modified)

    ' Check the DataSet for errors.
    If tempDataSet.HasErrors Then
       ' Insert code to resolve errors.
    End If

    ' After fixing errors, update the data source with 
    ' the DataAdapter used to create the DataSet.
    myOleDbDataAdapter.Update(tempDataSet)
End Sub

こちらもご覧ください

適用対象

HasChanges(DataRowState)

ソース:
DataSet.cs
ソース:
DataSet.cs
ソース:
DataSet.cs

DataSetDataRowState でフィルター処理された新しい行、削除された行、変更された行などの変更があるかどうかを示す値を取得します。

public:
 bool HasChanges(System::Data::DataRowState rowStates);
public bool HasChanges (System.Data.DataRowState rowStates);
member this.HasChanges : System.Data.DataRowState -> bool
Public Function HasChanges (rowStates As DataRowState) As Boolean

パラメーター

rowStates
DataRowState

DataRowState 値のいずれか 1 つ。

戻り値

DataSet に変更がある場合は true。それ以外の場合は false

次の例では、 メソッドを GetChanges 使用して 2 つ目 DataSet のオブジェクトを作成し、データ ソースの更新に使用します。

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);
}
Private Sub UpdateDataSet(ByVal dataSet As DataSet)
   ' Check for changes with the HasChanges method first.
   If Not dataSet.HasChanges(DataRowState.Modified) Then 
       Exit Sub
   End If

   ' Create temporary DataSet variable and
   ' GetChanges for modified rows only.
   Dim tempDataSet As DataSet = _
       dataSet.GetChanges(DataRowState.Modified)

   ' Check the DataSet for errors.
   If tempDataSet.HasErrors Then
      ' Insert code to resolve errors.
   End If

   ' After fixing errors, update the data source with   
   ' the DataAdapter used to create the DataSet.
   adapter.Update(tempDataSet)
End Sub

注釈

メソッドを HasChanges 呼び出す前に、 DataSet の プロパティを GetChanges 調べます。

こちらもご覧ください

適用対象