当数据数量达到限制时,如何防止用户插入相同的数据?

发布于 2025-02-10 06:33:20 字数 1490 浏览 1 评论 0原文

我正在为我的项目使用vb.net和SQL。我为我的问题提供了一个情况:

表数量

id    Pro_no    Quantity 
1      123          4
2      456          5

表insertdata

id    Pro_no     Quantity    Description    
1      123           2         broken
2      123           1       missing part

,您可以看到用户插入了pro_no 123 in insertdata表。这意味着它具有1更多数量可以插入。我的问题是,当有2个用户或用户打开具有2个选项卡的相同数据时,想要同时插入数据时,其中一个或其中一个选项卡将无法成功执行此操作,因为它已经达到了极限。

sql:

INSERT INTO insertData (Pro_no, Quantity,Description)
VALUES ('123','1','broken')

vb.net

    Protected Sub btnCreate_Click(sender As Object, e As EventArgs) Handles btnCreate.Click
        If ErrorChecking() = True Then
            DataInsert()
            DisplayMessage("success", "Done", "Data Succesfully Inserted!")
            clearAll()
        End If
    End Sub

datainsert()函数:

Private Function DataInsert() As Integer
        Using create As New clsQuantityProject_dal
            Dim obj As New clsQuantityProject_info
            With obj
                .Part_No = txtPartNo.Text
                .Description = txtDesc.Text
                .QTY = spinEditQTY.Text
            End With

            Dim strResult As Integer = create.QuantityDataInsert(obj)

        End Using
        Return 1
End Function

注意:请告诉我,如果您无法理解我的问题,我会纠正并更好地解释它

I'm using VB.net and SQL for my project. I give a situation for my problem:

Table Quantity

id    Pro_no    Quantity 
1      123          4
2      456          5

Table insertData

id    Pro_no     Quantity    Description    
1      123           2         broken
2      123           1       missing part

As you can see user has inserted Pro_no for 123 into the insertData table. Meaning that it has 1 more Quantity can be inserted. My problem is when there are 2 users OR user open the same data with 2 tabs, want to insert the data at the same time, one of them OR one of the tab will not successful to do it cause it has reached the limit.

SQL :

INSERT INTO insertData (Pro_no, Quantity,Description)
VALUES ('123','1','broken')

VB.net

    Protected Sub btnCreate_Click(sender As Object, e As EventArgs) Handles btnCreate.Click
        If ErrorChecking() = True Then
            DataInsert()
            DisplayMessage("success", "Done", "Data Succesfully Inserted!")
            clearAll()
        End If
    End Sub

DataInsert() Function :

Private Function DataInsert() As Integer
        Using create As New clsQuantityProject_dal
            Dim obj As New clsQuantityProject_info
            With obj
                .Part_No = txtPartNo.Text
                .Description = txtDesc.Text
                .QTY = spinEditQTY.Text
            End With

            Dim strResult As Integer = create.QuantityDataInsert(obj)

        End Using
        Return 1
End Function

note: do tell me if you can't understand my question, I'll correct and explain it better

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文