DataSet.HasChanges 方法

定義

取得值,表示 DataSet 是否包含變更,包括加入、刪除或修改的資料列。

多載

HasChanges()

取得值,表示 DataSet 是否包含變更,包括加入、刪除或修改的資料列。

HasChanges(DataRowState)

取得值,指出 DataSet 是否包含變更,包括加入、刪除或修改的資料列 (由 DataRowState 篩選)。

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 使用 方法來建立第二 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

取得值,指出 DataSet 是否包含變更,包括加入、刪除或修改的資料列 (由 DataRowState 篩選)。

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 值。

傳回

DataSet 包含變更,則為 true;否則為 false

範例

下列範例會 GetChanges 使用 方法來建立第二 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叫用 GetChanges 方法之前檢查 的 DataSet 屬性。

另請參閱

適用於