web analytics
Row States and Row Versions Options
codeling
Posted: Sunday, February 26, 2017 9:44:03 PM

Rank:Advanced Member
Groups: Member
Joined: 12/11/2015
Posts: 738
Points: 3102

ADO.NET manages rows in tables using row states and versions. A row state indicates the status of a row; row versions maintain the values stored in a row as it is modified, including current, original, and default values. For example, after you have made a modification to a column in a row, the row will have a row state of Modified, and two row versions: Current, which contains the current row values, and Original, which contains the row values before the column was modified.

When AcceptChanges is called on a DataSet, DataTable, or DataRow, all rows with a row state of Deleted are removed. The remaining rows are given a row state of Unchanged, and the values in the Original row version are overwritten with the Current row version values. When RejectChanges is called, all rows with a row state of Added are removed. The remaining rows are given a row state of Unchanged, and the values in the Current row version are overwritten with the Original row version values.

Sponsor
Posted: Sunday, February 26, 2017 9:44:03 PM
codeling
Posted: Sunday, February 26, 2017 9:46:02 PM

Rank:Advanced Member
Groups: Member
Joined: 12/11/2015
Posts: 738
Points: 3102

Each DataRow object has a RowState property that you can examine to determine the current state of the row. The following table gives a brief description of each RowState enumeration value.

RowState value

Description

Unchanged

No changes have been made since the last call to AcceptChanges or since the row was created by DataAdapter.Fill.

Added

The row has been added to the table, but AcceptChanges has not been called.

Modified

Some element of the row has been changed.

Deleted

The row has been deleted from a table, and AcceptChanges has not been called.

Detached

The row is not part of any DataRowCollection. The RowState of a newly created row is set to Detached. After the new DataRow is added to the DataRowCollection by calling the Add method, the value of the RowState property is set to Added.

Detached is also set for a row that has been removed from a DataRowCollection using the Remove method, or by the Delete method followed by the AcceptChanges method.

codeling
Posted: Sunday, February 26, 2017 9:57:52 PM

Rank:Advanced Member
Groups: Member
Joined: 12/11/2015
Posts: 738
Points: 3102

The following table gives a brief description of each DataRowVersion enumeration value.

 

DataRowVersion value

Description

Current

The current values for the row. This row version does not exist for rows with a RowState of Deleted.

Default

The default row version for a particular row. The default row version for an Added, Modified, or Unchanged row is Current. The default row version for a Deleted row is Original. The default row version for a Detached row is Proposed.

Original

The original values for the row. This row version does not exist for rows with a RowState of Added.

Proposed

The proposed values for the row. This row version exists during an edit operation on a row, or for a row that is not part of a DataRowCollection.

codeling
Posted: Sunday, February 26, 2017 10:00:07 PM

Rank:Advanced Member
Groups: Member
Joined: 12/11/2015
Posts: 738
Points: 3102

The following code example displays the values in all the deleted rows of a table. Deleted rows do not have a Current row version, so you must pass DataRowVersion.Original when accessing the column values.

DataTable catTable = catDS.Tables["Categories"];

DataRow[] delRows = catTable.Select(null, null, DataViewRowState.Deleted);

Console.WriteLine("Deleted rows:\n");

foreach (DataColumn catCol in catTable.Columns)
  Console.Write(catCol.ColumnName + "\t");
Console.WriteLine();

foreach (DataRow delRow in delRows)
{
  foreach (DataColumn catCol in catTable.Columns)
    Console.Write(delRow[catCol, DataRowVersion.Original] + "\t");
  Console.WriteLine();
}

Users browsing this topic
Guest

Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.


© 2017 Digcode.com. All rights reserved.