Explanation
- A DataRow has the RowState "Added", when it is newly added to the
Table After calling
AcceptChanges()
the RowState will be set to
"Unchanged"
- A DataRow has the DataRowVersion "Original", when it contains it's
original values. When calling
AcceptChanges()
on the DataRow, or DataTable the DataRowVersion will be set to "Original". You could say that original means all changes have been accepted.
- A DataRow has the RowState "Modified" after it has been edited.
Example Program
I have created a small example program, which shows the changes in action, to clarify the differences.
class Program {
static void Main(string[] args) {
var table = new DataTable("MyTable");
table.Columns.Add(new DataColumn("MyColumn"));
var row = table.NewRow();
Console.WriteLine($"Rowstate: {row.RowState}"); //Prints Detached
table.Rows.Add(row);
Console.WriteLine($"Rowstate: {row.RowState}"); //Prints Added
table.AcceptChanges();
Console.WriteLine($"Rowstate: {row.RowState}"); //Prints Unchanged
row.BeginEdit();
row[0] = "NewValue";
row.EndEdit();
Console.WriteLine($"Rowstate: {row.RowState}"); //Prints Modified
if (row.HasVersion(DataRowVersion.Current)) { // Does the row contain uncommited values?
Console.WriteLine($"DataRowVersion: {DataRowVersion.Current}"); //Prints Current
}
table.AcceptChanges(); //Commit all DataRowChanges
if (row.HasVersion(DataRowVersion.Original)) {
Console.WriteLine($"DataRowVersion: {DataRowVersion.Original}"); //Prints Current
}
Console.ReadLine();
}
}
Further Reading
The msdn documentation about DataRowStates is actually pretty well explained. It provides a short explanation about every single state aswell as some example code. Thats the same for DataRowVersions. You should definetly have a look at these 2 articles.
DataRowVersion
Quote from linked MSDN article:
After calling the DataRow object's BeginEdit method, if you change the
value, the Current and Proposed values become available.
After calling the DataRow object's CancelEdit method, the Proposed value is deleted.
After calling the DataRow object's EndEdit method, the Proposed value becomes the Current value.
After calling the DataRow object's AcceptChanges method, the Original value becomes identical to the Current value.
After calling the DataTable object's AcceptChanges method, the Original value becomes identical to the Current value.
After calling the DataRow object's RejectChanges method, the Proposed value is discarded, and the version becomes Current.