System.Data Namespace DataSet Class
Returns a copy of the DataSet containing all changes made to it since it was last loaded, or since AcceptChanges was called, filtered by DataRowState.
[ VB ]
Overloads Public Function GetChanges ( _
ByVal rowStates As DataRowState _
) As DataSet
[ C# ]
public DataSet GetChanges (
DataRowState rowStates
);
[ C++ ]
public: DataSet* GetChanges (
DataRowState rowStates
);
[ JScript ]
public function GetChanges (
rowStates : DataRowState
) : DataSet;
- rowStates
- One of the DataRowState values.
A filtered copy of the DataSet that can have actions performed on it, and subsequently be merged back in using Merge. If no rows of the desired DataRowState are found, the method returns a null reference.
The GetChanges method is used to produce a second DataSet object which contains only the changes introduced into the original. Use the rowStates argument to specify the type of changes the new object should include.
This copy is particularly designed so that it can be merged back in to this original DataSet. Relationship constraints may cause parent rows that are not of the specified rowState to also be included.
This returned copy is designed to be merged back in to this original DataSet. Relationship constraints may cause parent rows marked Unchanged to be included. If no rows of the desired DataRowState are found, the GetChanges method returns a null reference.
The following example uses the GetChanges method to create a second DataSet object that is then used to update a data source.
private void UpdateDataSet ( DataSet myDataSet ) {
// check for changes with the HasChanges method first.
if ( !myDataSet.HasChanges ( DataRowState.Modified ) ) return;
// create temporary DataSet variable.
DataSet xDataSet;
// getChanges for modified rows only.
xDataSet = myDataSet.GetChanges ( DataRowState.Modified );
// check the DataSet for errors.
if ( xDataSet.HasErrors ) {
// ... insert code to resolve errors here ...
}
// after fixing errors, update the DBMS with the DataAdapter
// used to create the DataSet.
myOleDbDataAdapter.Update ( xDataSet );
}
Private Sub UpdateDataSet ( ByVal myDataSet As DataSet )
' check for changes with the HasChanges method first.
If Not myDataSet.HasChanges ( DataRowState.Modified ) Then Exit Sub
' create temporary DataSet variable.
Dim xDataSet As DataSet
' getChanges for modified rows only.
xDataSet = myDataSet.GetChanges ( DataRowState.Modified )
' check the DataSet for errors.
If xDataSet.HasErrors Then
' insert code to resolve errors.
End If
' after fixing errors, update the DBMS with the DataAdapter
' used to create the DataSet.
myOleDbDataAdapter.Update ( xDataSet )
End Sub |
|
C# |
VB |
DataSet Members DataSet.GetChanges Overload List HasChanges HasErrors