Re: tricky TimeSpan editing
- From: "Bruce Wood" <brucewood@xxxxxxxxxx>
- Date: 25 Apr 2005 11:39:04 -0700
You have to worry about concurrency checking anyway. Between the time
you grab all of the TimeEntrys for the person for the day and the time
you update them, something could have changed on the back end. It
doesn't matter if you do the updates all together or one at a time.
Same problem.
In order to get your head around the problem, I would break it down
this way.
First, realize that there is always the chance that an update will
fail. Given that, you want to make the operation "atomic" at the user
level. That is, the user changes a start time, or an end time, or adds
a new TimeEntry, which causes other entries to be changed as a result.
The user is expecting that either "their" update works or it fails
because someone else is changing the same person for the same day. So,
from the user's point of view, if there are two operations needed in
order to update the TimeEntrys to reflect the user's (single) change,
then the user wants _both_ of those operations to either succeed or
fail.
This tells me that you want to make all of the changes in your
disconnected dataset, and then commit those changes to the database all
at once. By this, I _don't_ mean that you want to save up multiple
changes made by the user. You want to commit each user change as it
happens, and tell the user if it didn't work. However, you _do_ want to
send together the two or three updates necessary in order to implement
one time change.
The only thing I don't know how to do in ADO.NET is to tell it that all
updates / inserts must succeed or fail together as a _transaction_.
Does ADO.NET have transactions? I'm not enough of an ADO.NET guru to
know. I took a quick look at the SDK documentation:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconperformingtransactionusingadonet.asp
It looks as though you might even be able to leave your code as it
is... just use BeginTransaction and Commit or Rollback (if you get any
errors) on your Connection object... but as I said, I've never done it,
so I don't know exactly how it works.
Something I have done, and which I recommend, is use a DataAdapter to
describe the relationship between your ADO.NET in-memory, disconnected
DataSet and your database tables. Then you can make changes to the
DataTable in response to a user action, and Commit the changes. I'm
thinking it would look something like this:
DataSet personDay = ... fetch the data for a person for a day ...
user makes a change
myConnection.BeginTransaction
change DataTable in response to user's action
personDay.Commit -- commits changes back to database
if Commit succeeded
myConnection.Commit -- commits transaction
else
myConnection.Rollback -- undoes all changes
warn user that change didn't "take" because someone else is
modifying
endif
....or something like that. Perhaps someone with more experience in this
area can correct me, or supply better pseudo-code. :)
.
- Follow-Ups:
- Re: tricky TimeSpan editing
- From: DKode
- Re: tricky TimeSpan editing
- References:
- tricky TimeSpan editing
- From: DKode
- Re: tricky TimeSpan editing
- From: Bruce Wood
- Re: tricky TimeSpan editing
- From: DKode
- Re: tricky TimeSpan editing
- From: Bruce Wood
- Re: tricky TimeSpan editing
- From: DKode
- tricky TimeSpan editing
- Prev by Date: StreamReader.ReadLine()
- Next by Date: Re: Windows Service and EventLog
- Previous by thread: Re: tricky TimeSpan editing
- Next by thread: Re: tricky TimeSpan editing
- Index(es):
Relevant Pages
|