如何在使用 .net 时锁定记录以进行编辑
大家好,当管理员和用户想要同时编辑数据库中的同一记录时,我想锁定一条记录以防止编辑
using (SqlCommand cmd = Connection.CreateCommand())
{
cmd.CommandType = CommandType.Text;
cmd.CommandText = @"
UPDATE [dbo].[Property]
SET {not important}IS NULL THEN NULL
ELSE geography::Point(@Location_Lat, @Location_Long, 4326)
END)
{not important}
WHERE [Id] = @Id";
cmd.Parameters.AddParams(property);
cmd.Connection.Open();
try
{
cmd.ExecuteNonQuery();
}
finally
{
cmd.Connection.Close();
}
}
Hi Guys I'd like to lock a record to prevent editing when Admin and User want to editing the same record in DB in the same time
using (SqlCommand cmd = Connection.CreateCommand())
{
cmd.CommandType = CommandType.Text;
cmd.CommandText = @"
UPDATE [dbo].[Property]
SET {not important}IS NULL THEN NULL
ELSE geography::Point(@Location_Lat, @Location_Long, 4326)
END)
{not important}
WHERE [Id] = @Id";
cmd.Parameters.AddParams(property);
cmd.Connection.Open();
try
{
cmd.ExecuteNonQuery();
}
finally
{
cmd.Connection.Close();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论