如何防止更多用户在同一个记录中编辑我... [英] How Prevent more user from edit in same recorddo I...

查看:73
本文介绍了如何防止更多用户在同一个记录中编辑我...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我需要更新员工如下

CREATE PROC UPDATE_EMPLOYEE



@EmployeeID INT,

@EmployeeName NVARCHAR(50)



AS

更新员工设置EmployeeName = @ EmployeeName其中EmployeeID = @ EmployeeID

假设我有两个用户A,B

使用存储过程修改或编辑上面员工编号5000字段EmployeeName

B需要修改员工编号5000存储过程上面的字段EmployeeName

i需要阻止用户B使用时间戳修改相同的记录如何从c#代码和sql server执行此操作以及存储过程中接受时间戳的修改

EmployeeTable

EmployeeID

EmployeeName

TimeStampEmp

含义在指定时间后允许其他用户

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

推荐答案

您不会阻止2个人同时编辑同一个记录。当你把数据写入数据库时​​,你会检查这个。



你有几个选择。



1)最后一次写入数据库总是获胜。没有检查。你只需将记录写入数据库,最后到达那里的人被认为是最新的和正确的数据。



2)你去写数据到数据库在SQL UPDATE语句中,将WHERE子句设置为包括表中的每个字段,而不仅仅是记录ID。这样,如果受影响的记录值返回1以外的任何值,您就会知道数据在检索时间和您尝试再次保存之间的时间之间发生了变化。
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.


这篇关于如何防止更多用户在同一个记录中编辑我...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆