使用编码自动生成ID [英] Generating ID automatically using coding

查看:178
本文介绍了使用编码自动生成ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Dim RandomGenerator As Random
Dim intRandomNumber As Integer

RandomGenerator = New Random()
intRandomNumber = RandomGenerator.Next(100, 1000)


我已经使用上面的编码为数据库中的表生成了ID,但是该ID不会自动生成..


I have using the above coding to generate id for my table in database but the id does not generate automatically..

推荐答案

第一个问题是,为什么要在您的应用程序中生成一个ID?例如,如果您使用的是SQL Server,则可以将ID列定义为标识( http://msdn.microsoft.com/en-us/library/ms186775.aspx [
The first question is, why do you want to generate an ID in your application? IF you''re using SQL Server for example, then you can define the ID column as identity (http://msdn.microsoft.com/en-us/library/ms186775.aspx[^]).

Another thing is that if you just generate random numbers it''s quite likely that you get the same number at some point so it wouldn''t serve as a unique ID.


这篇关于使用编码自动生成ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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