Make changes to record

  • Thread starter Thread starter pcPirate
  • Start date Start date
P

pcPirate

Hi,

I have an application, the user are able to change records in this
application.
Also, there's a button called "What If".

After the user pressed the "What If" button, the user may change the records
and save it. When the user open the same record again, all the changes is
there. (Pls. notice that the user is still in the "What If" environment).
Somehow the changes are save to a mirror table record.

The changes would only affect the real records until the user press another
button called "Accept changes", in which all the changes in the mirrored
table would be adapted into the real record.

Is there any way i can do it via C# and MS Sql Database?

Pls. advice and thanks in advance
 
Hi pcPirate

Load your data into a dataset. You could use an adapter and the Fill method for doing this. I will assume you know that

Changes made to a datatable are stored in different states. Unless you call the AcceptChanges method of the datatable/dataset/datarow, changes won't be reflected. So when a user makes changes, the changes are not yet reflected to the actual db (just the way u said); instead, they are stored in the dataset

When you update the SQL server db through the dataadapter, AcceptChanges method is called finally, which will make it reflect it to the real-world (sql db). So, when the user clicks on 'Accept Changes', you could call the Update method of the dataadapter to update the db

HTH,

Warm regards
fbhca
 
Hi,

Note here:
AcceptChanges method just consolidates DataRow/DataTable/DataSet state and
make all rows as RowState.Unchanged.
It does nothing else.

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

fbhcah said:
Hi pcPirate,

Load your data into a dataset. You could use an adapter and the Fill
method for doing this. I will assume you know that.
Changes made to a datatable are stored in different states. Unless you
call the AcceptChanges method of the datatable/dataset/datarow, changes
won't be reflected. So when a user makes changes, the changes are not yet
reflected to the actual db (just the way u said); instead, they are stored
in the dataset.
When you update the SQL server db through the dataadapter, AcceptChanges
method is called finally, which will make it reflect it to the real-world
(sql db). So, when the user clicks on 'Accept Changes', you could call the
Update method of the dataadapter to update the db.
 
Hi,

Thanks for replying.
So, what you mean here is that, I'd first need to put all the changes into
the disconnected dataset, right?

Actually, when the user press the "What If" button, they would be in the
"What If" environment. The user may save the records and manage to display
the record anytime they want. Pls. notice, the user still in "What If"
environment in this moment.

When the user has seen that all the records are correctly entered, the user
would press the "Accept Changes" button (which is available in the menu).
Then, all the records which has been save during the "What If" environment
would be transfer to the actual database table.

If the user press "Discard Changes", all the records save during the "What
If" environment would all be discard.

I hope this would state my question clearer.

Pls. advice and thanks in advance.
 
Back
Top