How to prevent users insert the same data when the quantity of the data has reached its limit?

76 Views Asked by At

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

0

There are 0 best solutions below