gpt4 book ai didi

asp.net - 插入/更新表的好习惯或坏习惯

转载 作者:行者123 更新时间:2023-12-04 04:56:01 24 4
gpt4 key购买 nike

我在网站上有一个页面,用户可以在其中使用两个列表框和两个按钮编辑民意调查中的问题,我正在考虑这样做:

Questions in the poll             Questions available
1 [>]1 0
3 [<]2 2
6 4
9 5
7
8
10

以下是按钮的作用:

  • 从“投票中的问题”中退出选择
  • 将“可用问题”中选择的添加到“投票中的问题”

  • 以我的方式,我会在 buttonClick 事件的民意调查中将问题插入/删除到/从表中插入/删除,但是如果有人在回答民意调查并且问题消失了,这会造成麻烦......

    你们会怎么做?我正在使用 ASP.NET + VB.NET,但我不想要“teh codez”,我只想要您对如何执行此操作的意见。谢谢:)

    最佳答案

    使用读/写锁来保护表?

    您可以通过多种方式实现乐观锁,但实现乐观锁的基本原理是相同的。这是一个 4 步过程,如下所示:-

    • Record the current timestamp.
    • Start changing the values.
    • Before updating check whether anyone else has changed the values by checking the old time stamp and new time stamp.
    • If it’s not equal rollbacks or else commit.

    我们可以通过 3 种主要方式在 .NET 中实现乐观锁定:-
    • Datasets: - Dataset by default implement optimistic locking. They do a check of old values and new values before updating.
    • Timestamp Data type: - Create a timestamp data type in your table and while updating check if old timestamp is equal to new timestamp.
    • Check old and new value: - Fetch the values, do the changes and while doing the final updates check if the old value and current values in database are equal. If they are not equal then rollback or else commits the values.

    锁定模式:
    Shared: 
    Used for read operations that do not change or update data, such as a SELECT statement.

    Update:
    Used on resources that can be updated. Prevents a common form of deadlock that occurs when multiple sessions are reading, locking, and potentially updating resources later.

    Exclusive:
    Used for data-modification operations, such as INSERT, UPDATE, or DELETE. Ensures that multiple updates cannot be made to the same resource at the same time.

    Intent:
    Used to establish a lock hierarchy. The types of intent locks are: intent shared (IS), intent exclusive (IX), and shared with intent exclusive (SIX).

    Schema:
    Used when an operation dependent on the schema of a table is executing. The types of schema locks are: schema modification (Sch-M) and schema stability (Sch-S).

    Bulk Update:
    Used when bulk copying data into a table and the TABLOCK hint is specified.

    Key-range:
    Protects the range of rows read by a query when using the serializable transaction isolation level. Ensures that other transactions cannot insert rows that would qualify for the queries of the serializable transaction if the queries were run again.

    还有 this article应该有帮助。

    关于asp.net - 插入/更新表的好习惯或坏习惯,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16745936/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com