[Vb.net + ms.access]如何创建一个唯一的ID? [英] [Vb.net+ms.access] how to create a unique id?

查看:68
本文介绍了[Vb.net + ms.access]如何创建一个唯一的ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中,我的一个表单需要记录订单,同时自动为它们生成唯一的ID。 id应该是数字。

在之前的尝试中,我试图获取数据库+ 1中的记录数量作为Id。但是表单有一个删除记录的删除功能。当中间的记录被删除时(例如:5个中的3个),生成的下一个id将为5,这将导致错误。

有关创建唯一ID的建议吗?充其量,它不会打扰数据库。在此先感谢



我尝试过:



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

推荐答案

使用您的id的自动编号字段类型获取数据库为您生成ID。
Get the database to generate the ID for you by using the autonumber field type for your id.


这篇关于[Vb.net + ms.access]如何创建一个唯一的ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆