DataTable.GetChanges 方法   
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取 DataTable 的副本,该副本包含自上次加载以来或自调用 AcceptChanges() 以来的所有更改。
重载
| GetChanges() | 获取 DataTable 的副本,该副本包含自加载以来或自上次调用 AcceptChanges() 以来进行的所有更改。 | 
| GetChanges(DataRowState) | 获取由 DataRowState 筛选的 DataTable 的副本,该副本包含上次加载以来或调用 AcceptChanges() 以来进行的所有更改。 | 
GetChanges()
- Source:
- DataTable.cs
- Source:
- DataTable.cs
- Source:
- DataTable.cs
获取 DataTable 的副本,该副本包含自加载以来或自上次调用 AcceptChanges() 以来进行的所有更改。
public:
 System::Data::DataTable ^ GetChanges();public System.Data.DataTable? GetChanges ();public System.Data.DataTable GetChanges ();member this.GetChanges : unit -> System.Data.DataTablePublic 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中没有包含挂起更改Nothing的行,则该方法在 Visual Basic) 中返回 null (。
另请参阅
适用于
GetChanges(DataRowState)
- Source:
- DataTable.cs
- Source:
- DataTable.cs
- Source:
- DataTable.cs
获取由 DataRowState 筛选的 DataTable 的副本,该副本包含上次加载以来或调用 AcceptChanges() 以来进行的所有更改。
public:
 System::Data::DataTable ^ GetChanges(System::Data::DataRowState rowStates);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.DataTablePublic Function GetChanges (rowStates As DataRowState) As DataTable参数
- rowStates
- DataRowState
DataRowState 值之一。
返回
              DataTable 的筛选副本,可以对该副本执行操作,之后可以使用 DataTable 将其合并回 Merge(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使用 参数指定新对象应包含的更改的类型。
关系约束可能会导致包含未更改的父行。