How can I get a specific version of a dataset row?

2019-07-10 02:23发布

问题:

using a dataset,each row has a method called hasVersion() which implies to me it keeps a copy of the original and current versions of that row. How can I get one of the original row values?

I'd imagine it's possible to call reject changes on that row and then check the value, but I'd rather not lose the changes, just read the value(s).

回答1:

If you are looking at a particular row, you can get a particular version of the row's values through the DataRowVersion enumeration thru one of the overloads, e.g.

SomeDataRow[0, DataRowVersion.Original] //by index
SomeDataRow["ColumnName", DataRowVersion.Original] //by column name

Along with that, you might want to use the GetChanges() method on the datatable. Pass in a DataRowState (in your case, DataRowState.Modified), then use the above to get the original value of any rows that have changed.



标签: .net dataset