System.Data Namespace DataSet Class
Checks whether the DataSet has changes, including new, deleted, or modified rows, filtered by DataRowState.
[ VB ]
Overloads Public Function HasChanges ( _
ByVal rowStates As DataRowState _
) As Boolean
[ C# ]
public bool HasChanges (
DataRowState rowStates
);
[ C++ ]
public: bool HasChanges (
DataRowState rowStates
);
[ JScript ]
public function HasChanges (
rowStates : DataRowState
) : Boolean
- rowStates
- One of the DataRowState values: Detached, Unchanged, New, Deleted, and Modified.
This method returns only a boolean value: true, if the DataSet has changes; otherwise, false.
The property is read only with no default value.
Examine the HasChanges property before invoking GetChanges method.
The following example uses the GetChanges method to create a second DataSet object that is then used to update a DBMS.
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 db with the DataAdapter used to fill the DataSet.
myDataAdapter.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 here ...
End If
' after fixing errors, update db with the DataAdapter used to fill the DataSet.
myDataAdapter.Update ( xDataSet )
End Sub |
|
C# |
VB |
DataSet Members DataSet.HasChanges Overload List GetChanges HasErrors