DataTable.GetChanges 方法

定義

會取得一份包含自上次載入或調用以來AcceptChanges()所有變更的副本DataTable

多載

名稱 Description
GetChanges()

會取得一份包含自載入AcceptChanges()或最後調用以來所有變更的 的DataTable副本。

GetChanges(DataRowState)

會取得一份包含自上次載入或AcceptChanges()被呼叫以來所有變更的副本DataTable,並被 DataRowState過濾。

GetChanges()

會取得一份包含自載入AcceptChanges()或最後調用以來所有變更的 的DataTable副本。

public:
 System::Data::DataTable ^ GetChanges();
public System.Data.DataTable GetChanges();
member this.GetChanges : unit -> System.Data.DataTable
Public Function GetChanges () As DataTable

傳回

請提供該變更 DataTable的副本,或 null 若未找到變更。

範例

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 的副本。 如果未更改的列包含對應於外鍵的主鍵,則關係限制可能導致新增列中加入更多未更改的列。DataSet 若原始 DataSet 中沒有待處理的列,則該方法回傳 null(Visual Basic 中為 Nothing)。

另請參閱

適用於

GetChanges(DataRowState)

會取得一份包含自上次載入或AcceptChanges()被呼叫以來所有變更的副本DataTable,並被 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 價值。

傳回

經過篩選的 該複本DataTable可以執行操作,之後再合併回 DataTableMerge(DataSet) 若未找到所需 DataRowState 列,則返回 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

備註

GetChanges 方法用於產生 DataTable 第二個物件,僅包含原始物件中引入的變更。 使用 rowStates 參數指定新物件應包含的變更類型。

關係限制可能導致包含未變更的父列。

另請參閱

適用於