AngularJS is an open source JavaScript
Framework to build dynamic web pages, AngularJS provides a number of advantages
in designing and developing modern web applications the following are the list
of the major advantages of using AngularJS.
Showing posts with label AcceptChanges. Show all posts
Showing posts with label AcceptChanges. Show all posts
Saturday, February 7, 2015
Tuesday, June 19, 2012
DataTable AcceptChanges
The DataTable’s AcceptChanges() method commits the
changed done to the DataRow and the DataTable’s RejectChanges() method rolls
back the changes done to the DataRow.
Now let us see with an example, on how the rowstate property
gets affected by calling the AcceptChanges() method of the DataTable.
Let us add a new
row to a DataTable, and perform various operations on the row to observer the
change in the RowState of the row.
// Fill the DataTable with your own logic
// Here we will fill the table by calling the Domain class.
clsEmployee objEmp = new
clsEmployee();
DataTable dtEmployee = objEmp.GetEmployeeList();
DataRow drEmp;
DataRow drEmp;
//
// Add a new Row and perform data changes
drEmp =
dtEmployee.NewRow(); // RowState - Detached
dtEmployee.Rows.Add(drEmp); // RowState - Added
dtEmployee.AcceptChanges(); // RowState - Unchanged
drEmp["ID"] = 3134; // RowState -
Modified
dtEmployee.AcceptChanges(); // RowState - Unchanged
drEmp.Delete(); // RowState -
Deleted
dtEmployee.AcceptChanges(); // RowState - Detached
gvEmployees.DataSource =
dtEmployee;
Notice that, every time you call the DataTable’s AcceptChanges()
method, the changes are committed to the DataTable and the RowState is reset to
Unchanged.
The following are the changes of RowState of the DataRows in the DataTable, before and after calling the DataTable’s AcceptChanges() method.
The following are the changes of RowState of the DataRows in the DataTable, before and after calling the DataTable’s AcceptChanges() method.
RowState before calling AcceptChanges()
|
RowState after calling AcceptChanges()
|
Impact on the Row
|
Added
|
Unchanged
|
New row is commited to the DataTable
|
Modified
|
Unchanged
|
Data Changes to the row are committed to
the DataTable
|
Deleted
|
Detached
|
Row is Permanently Removed from the
DataTable
|
The AcceptChange() method can also be called on the individual
DataRows in the DataTable, calling the DataTable’s AcceptChanges() method, will
commit the changes of all the DataRows in the DataTable.
To know more on the DataTable’s RejectChanges() method,
refer the post DataTable RejectChanges.
Related Posts
DataRow RowState
DataTable AcceptChanges
DataTable RejectChanges
Get new rows in a DataTable / DataGridView in C# Windows Forms
Get Modified rows in a DataTable / DataGridView in C# Windows Forms
Get Deleted rows in a DataTable / DataGridView in C# Windows Forms
Related Posts
DataRow RowState
DataTable AcceptChanges
DataTable RejectChanges
Get new rows in a DataTable / DataGridView in C# Windows Forms
Get Modified rows in a DataTable / DataGridView in C# Windows Forms
Get Deleted rows in a DataTable / DataGridView in C# Windows Forms
DataRow RowState
The RowState is a very useful property of a DataRow, it
gives the current state of the row. The state of the row is affected based on
the operations performed on the row, like Add, Modify Delete. The RowState of a row can take one of the
following values.
- Detached
- Added
- Unchanged
- Modified
- Deleted
Let us add a new
row to a DataTable, and perform various operations on the row to observer the
change in the RowState of the row.
// Fill the DataTable with your own logic
// Here we will fill the table by calling the Domain class.
clsEmployee objEmp = new
clsEmployee();
DataTable dtEmployee = objEmp.GetEmployeeList();
DataRow drEmp;
DataRow drEmp;
//
// Add a new Row and perform data changes
drEmp =
dtEmployee.NewRow(); // RowState -
Detached
dtEmployee.Rows.Add(drEmp); // RowState
- Added
drEmp["ID"] = 3134; //
RowState - Added
drEmp.Delete(); //
RowState - Detached
//
drEmp =
dtEmployee.NewRow(); // RowState - Detached
dtEmployee.Rows.Add(drEmp); // RowState
- Added
dtEmployee.AcceptChanges(); // RowState
- Unchanged
drEmp["ID"] = 3134; //
RowState - Modified
drEmp.Delete(); //
RowState – Deleted
Notice that in the first block, the RowState is not
changed, this is because we did not call the DataTable’s AcceptChanges() method,
thought we performed an edit operation in the row, the RowState still remained Added.
The DataTable’s AcceptChanges()
method commits the changes to the DataTable. In the 2nd code block,
we called the DataTable’s AcceptChanges() method after adding the row to the
table, hence the RowState gets changed after performing a Modify/Delete
operation.
The DataTable’s AcceptChanges() method commits the
changed done to the DataRow and the DataTable’s RejectChanges() method rolls
back the changes done to the DataRow. To know more about these methods refer
the posts
.
Related Posts
Get Deleted rows in a DataTable / DataGridView in C# Windows Forms
.
Related Posts
Get Deleted rows in a DataTable / DataGridView in C# Windows Forms
Subscribe to:
Posts (Atom)