Click here to Skip to main content
15,883,922 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
suppose i need to make update the employee as following
CREATE PROC UPDATE_EMPLOYEE
(
@EmployeeID INT,
@EmployeeName NVARCHAR(50)
)
AS
update Employee set EmployeeName=@EmployeeName where EmployeeID=@EmployeeID
Suppose I have two useres A,B
A modified or edit using stored procedure above employee no 5000 field EmployeeName
B need to modify employee no 5000 using stored procedure above field EmployeeName
i need to prevent user B To modify same record using time stamp How to do that from c# code and sql server and what modification in stored procedure to accept timestamp
EmployeeTable
EmployeeID
EmployeeName
TimeStampEmp
Meaning allow to another user after specified time
Posted
Comments
[no name] 25-Feb-15 15:38pm    
Think again about whether you really have to prevent. Is it a difference whether B modifies after 1milliSec or by Chance 5Sec ("the specified time") after A modified it?
ZurdoDev 25-Feb-15 16:02pm    
Where are you stuck?
HKHerron 25-Feb-15 16:16pm    
I think he is trying to prevent 2 people from editing the same record at the same time??

1 solution

You don't prevent 2 people from editing the same record at the same time. You check this when you go to write the data to the database.

You have a couple of options.

1) The last write to the database always wins. No checking involved. You simple just write the record to the database and whoever gets there last is considered the most current and correct data.

2) You go to write the data to the database and in your SQL UPDATE statement, you set your WHERE clause to include every field in the table, not just the record ID. This way, if the "records affected" value comes back with anything other than 1, you know the data was changed between the time it was retrieved and the time you're trying to save it again.
 
Share this answer
 
Comments
[no name] 27-Feb-15 13:09pm    
Straightforward and good explanation, +5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900