DataTable.GetChanges DataTable.GetChanges DataTable.GetChanges DataTable.GetChanges Method

定義

取得 DataTable (包含從前一次載入它或呼叫 AcceptChanges() 以來所做的所有變更) 的複本。Gets a copy of the DataTable containing all changes made to it since it was last loaded, or since AcceptChanges() was called.

多載

GetChanges() GetChanges() GetChanges() GetChanges()

取得 DataTable (包含從載入它或前一次呼叫 AcceptChanges() 以來所做的所有變更) 的複本。Gets a copy of the DataTable that contains all changes made to it since it was loaded or AcceptChanges() was last called.

GetChanges(DataRowState) GetChanges(DataRowState) GetChanges(DataRowState) GetChanges(DataRowState)

取得 DataTable (包含從前一次載入它或呼叫 AcceptChanges() 以來所做的所有變更) 的複本 (由 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() GetChanges() GetChanges() GetChanges()

取得 DataTable (包含從載入它或前一次呼叫 AcceptChanges() 以來所做的所有變更) 的複本。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 ();
member this.GetChanges : unit -> System.Data.DataTable
Public Function GetChanges () As DataTable

傳回

這個 DataTable 所產生變更的複本,如果沒有變更,則為 nullA copy of the changes from this DataTable, or null if no changes are found.

範例

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

備註

建立新DataSet的,其中包含原始DataSet中具有暫止變更之所有資料列的複本。Creates a new DataSet containing a copy of all rows in the original DataSet that have pending changes. 如果未變更的資料列包含對應于已變更資料列DataSet中外鍵的主鍵,則關聯性條件約束可能會導致其他未變更的資料列加入至新的。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. 如果原始null Nothing 中沒有具有暫止變更的資料列,方法會傳回(在DataSet Visual Basic 中)。The method returns null (Nothing in Visual Basic) if there are no rows in the original DataSet with pending changes.

另請參閱

GetChanges(DataRowState) GetChanges(DataRowState) GetChanges(DataRowState) GetChanges(DataRowState)

取得 DataTable (包含從前一次載入它或呼叫 AcceptChanges() 以來所做的所有變更) 的複本 (由 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);
member this.GetChanges : System.Data.DataRowState -> System.Data.DataTable
Public Function GetChanges (rowStates As DataRowState) As DataTable

參數

rowStates
DataRowState DataRowState DataRowState DataRowState

其中一個 DataRowState 值。One of the DataRowState values.

傳回

篩選過的 DataTable 複本,可以在其上執行動作,稍後會在 DataTable 中使用 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). 如果找不到所需的 DataRowState 的資料列,則方法會傳回 nullIf no rows of the desired DataRowState are found, the method returns null.

範例

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

備註

方法是用來產生第二個DataTable物件,其中只包含原始所引進的變更。 GetChangesThe GetChanges method is used to produce a second DataTable object that contains only the changes introduced into the original. rowStates使用引數來指定新物件應該包含的變更類型。Use the rowStates argument to specify the type of changes the new object should include.

關聯性條件約束可能會導致包含未變更的父資料列。Relationship constraints may cause unchanged parent rows to be included.

另請參閱

適用於