0

In C# I have a DataTable that has been modified several times, where some rows are deleted, some rows are updated, some rows remain the same.

DataTable detailsTable = GetDdetails();

Insert code that does the following:

  1. Sorts my DataTable according to specific column (myColumn ASC) based on current values in the rows (current values accessible through detailsTable.Rows[i]["ColumnName", DataRowVersion.Original])

  2. Preserves original data in the rows, because both, original and current values are used later in UseDetails function (values accessible through detailsTable.Rows[i]["ColumnName", DataRowVersion.Current])

Code:

UseDetails(detailsTable);

I encountered a few problems:

  1. Traditional way to sort values creates view from the detailsTable, which will not bring deleted rows in.

  2. Specifically including deleted fields (using filters) will remove their deleted status.

  3. Copying data from an unsorted table to sorted will throw an exception if attempting to access deleted field

Thank you in advance

1 Answer 1

0

You could keep a copy of the original dataset.

To make it easier you can create your own version of DataTable e.g.:

internal class DataTableWithOriginalData : DataTable
{
    public DataTableWithOriginalData(DataTable table) : base ()
    {
        OriginalData = table.Copy();        
    }

    public DataTable OriginalData { get; }
}
Sign up to request clarification or add additional context in comments.

1 Comment

thank you, but that's not what i was looking for: DataTable has data versioning feature, where within the same object/same row contains original, current, and scheduled values, as well as current state of the data row (modified, deleted, etc..). Im looking for a way to re-sort the data table based on its current values, while preserving historical data and current state for each Data row.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.