In my project, one of my form need to record the orders while automatically generate an unique ID for them. The id should be in numbers.
In previous attempt, I have tried to obtain the amount of records in database + 1 as the Id. But the form has a delete function that removes record. When a record in the middle is removed,(eg: 3 out of 5), the next id generated will be 5, which will cause error.
Any suggestion to create an unique Id? At best, it will not bother the database. Thanks in advance
What I have tried:
Dim count As Integer
Private Sub Order_Load(sender As Object, e As EventArgs) Handles MyBase.Load
count = OrderBindingSource.Count + 1
Me.OrderTableAdapter.Fill(Me.ORDDataSet.Order)
End Sub
Private Sub btnSubmit_Click(sender As Object, e As EventArgs) Handles btnSubmit.Click
If OrderQtyTextBox.Text = "" Then
MessageBox.Show("Please specify order quantity")
Else
count = count + 1
Dim Pqty As Integer
Integer.TryParse(PalletQtyTextBox.Text, Pqty)
OrderTableAdapter.Insert(OrderNoTextBox.Text, VendorIDTextBox.Text, ItemNoTextBox.Text, OrderQtyTextBox.Text, OrderDateDateTimePicker.Value, OrderDateDateTimePicker.Value, StatusTextBox.Text, MultipackQtyTextBox.Text, Pqty)
Me.OrderTableAdapter.Fill(Me.ORDDataSet.Order)
OrderNoTextBox.Text = count
OrderQtyTextBox.Text = ""
StatusTextBox.Text = ""
End If
End Sub