updating data on the same web form via 2 pc's

  • Thread starter Thread starter cmpcrand
  • Start date Start date
C

cmpcrand

if 2 people are working on the same web site is it possible to be able
to work on it Simultaneously so that if i for example was to change
something it would change on the other persons screen after a refresh
 
if 2 people are working on the same web site is it possible to be able
to work on it Simultaneously so that if i for example was to change
something it would change on the other persons screen after a refresh

Absolutely, assuming both users are working with the same data, and the data
is not user-specific...
 
for example, if you have a gridview on the page, and both users have the
gridview on screen with the same 20 records. they each edit a different row
and hit update or whatever. when the page reloads, they will see the
changes made by the other person. if they changed the same row, it will be
a case of "last one wins" unless you do some conflict checking in your
database code / layer.

tim
 
for example, if you have a gridview on the page, and both users have the
gridview on screen with the same 20 records. they each edit a different
row and hit update or whatever. when the page reloads, they will see the
changes made by the other person. if they changed the same row, it will
be a case of "last one wins"

Yes indeed.
unless you do some conflict checking in your database code / layer.

Doesn't everyone...?
 
unless you do some conflict checking in your database code / layer.
Doesn't everyone...?

i guess not, me at least! i never saw the point of the following delete
query (generated by VS / ado.net with optimistic concurrency)

delete from table where PK = 5 and
CompareEveryOtherColumnValueToSeeIfItChanged
i much prefer: delete from table where PK = 5

if a user wants to delete a record, it doesn't matter (to me at least)
whether the data changed or not, it is still destined for the trash, as
decided by the user. there is obviously very good reason for conflict
checking with update statements, but even then, one assumes that the user
would not want to proceed with the udpate if they knew that other values in
the record had changed. this wouldn't always be true. the user might prefer
that their statement get executed, rather than be told that someone else
beat them to it and have their statement rejected. in most of the apps i
develop, it doesn't matter if an edit is done and then silently overwritten
by a subsequent edit of the same record, typically because the data would be
overwritten anyway (with or without a conflict), in any case, there is no
effective loss of data. certainly there are situations where this is bad,
but i don't encounter them very often.

tim
 
decided by the user. there is obviously very good reason for conflict
checking with update statements, but even then, one assumes that the user
would not want to proceed with the udpate if they knew that other values
in the record had changed.

Ah yes, but what if they *didn't* know...?

Scenario:

User A opens Record 1

User B opens Record 1, having no clue that User A also has Record 1 open

User A changes 99 of the 100 fields in Record 1 and clicks the Save button

User A logs out

User B changes the other field in Record 1 and clicks the Save button,
thereby overwriting all of User A's changes

User B logs out

Neither User A nor User B has the slightest notion of what has just
happened, until / unless User A opens Record 1 again and wonders where all
the changes went...
 
If you're using SqlServer, you can use a DATATYPE called "timestamp".

A timestamp is a value that increments each time a record is updated. You
don't have to manually do this, it just happens.


Create Table dbo.Employee (EmpID int , RowVers timestamp , LastName
varchar(24 ) )

INSERT INTO dbo.Employee ( EmpID , LastName ) values ( 101, 'Jones' )
INSERT INTO dbo.Employee ( EmpID , LastName ) values ( 102, 'Smith' )
INSERT INTO dbo.Employee ( EmpID , LastName ) values ( 103, 'Gates' )

Select * from dbo.Employee

Select EmpID , convert ( int , RowVers ) as RowVersAsInt , LastName from
dbo.Employee

Converting to an int the easiest way to deal with this.

When you load an Employee (for possible edit) ...... you also persist (on
the webpage , or as custom business entity), the RowVersInt value.

Then when you update the Employee, you check to see if the RowVersInt has
changed.


@EmpID int
@LastName varchar(24)
@RowVersInt int

if exists (Select * from dbo.Employee e where e.EmpID = @EmpID and
convert(int , e.RowVers) <> @RowVersInt )
begin
err.raise 'Ahhhhhhhh, somebody already updated this employee',
.........................
end


something like that.
 
Back
Top