查看: 823|回复: 4
|
自动generate primary key
[复制链接]
|
|
How to auto generate a primary key in MS SQL server 2000?
I'm using vb.net to develop an asp.net web application...
I have a form which passes some fields into an SQL server database... I would like the primary key(form number) to be created automatically when a new record is inserted...
My friend told me that I can set this in the Enterprise Manager...but the problem is I do not have ms sql server installed in my pc...It's installed on the server....and i do the project on the server....
Hope someone can help me....Thanks!! 
p/s: 由于时间不足,所以用英文,请多多包涵! |
|
|
|
|
|
|
|
发表于 3-8-2006 09:19 AM
|
显示全部楼层
在 mssql, 你可以用 int 然后设定 seed + increment 来做一个 running number. 另外你可以用 uniqueidentifier 来做 primary key. 这些, 你可以用 sql 建立 table 的时候办到. |
|
|
|
|
|
|
|

楼主 |
发表于 3-8-2006 11:28 AM
|
显示全部楼层
我已经将FormNo设定为primary key,而且也把它换成int,还有设定identity=yes,seed=1和increment=1。我是不是该把它insert进database里?
以下是我放在submitbutton_clicked event的code(sample):
cmdInsert.Parameters.Add("@StaffNo", txtStaffNo.Text)
我需要加上类似的code吗?比如--> cmdInsert.Parameters.Add("@FormNo", ?????) |
|
|
|
|
|
|
|

楼主 |
发表于 3-8-2006 11:52 AM
|
显示全部楼层
不好意识,我还没test就问了一大堆。 非常神奇,只是设定identity=yes,identity seed=1,identity increment=1就可以了!谢谢!
此外,还有一个问题,就是要设定status=pending当submit一个新的form。我在另一个page有一个column(Status)是dropdownlist,它的item包括approved,pending,和rejected。用户可在那里更换Status。请问如何做到? |
|
|
|
|
|
|
|
发表于 3-8-2006 12:15 PM
|
显示全部楼层
原帖由 elfinxp 于 3-8-2006 11:52 AM 发表
不好意识,我还没test就问了一大堆。 非常神奇,只是设定identity=yes,identity seed=1,identity increment=1就可以了!谢谢!
此外,还有一个问题,就是要设定status=pending当submit一个新的form。我在另一 ...
这不就是一般的 form operation 吗? 你可以先 select 全部 status 然后放进 dropdown, 然后透过 dropdown 来 update 资料库. 你应该先试写, 然后有问题再 post 上来让大家看看. |
|
|
|
|
|
|
| |
本周最热论坛帖子
|