如何在asp.net中自动生成和记录数据库中用户的唯一ID [英] How to automatically generate and record unique ID of user in database in asp.net

查看:64
本文介绍了如何在asp.net中自动生成和记录数据库中用户的唯一ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Suppose I have unique ID kvk0001

where kvk is fixed 0001 is increment by one such as:
kvk0001,kvk0002,kvk0003.......

And unique ID kvk0001 is same id for each table of registration.





如何在C#中为上述案例开发代码ASP.NET?



how to develop a code for above case in C# & ASP.NET ?

推荐答案

最好参考:

http://www.sqlteam.com/article/custom-auto-generated-sequences-with-sql-server [ ^ ]


添加前缀/后缀。这样的东西应该有效:



1 - 添加一个IDENTITY字段,该字段将自动递增

2 - 添加一个计算字段表定义:



[InvoiceNo] AS('AS'+右(('000000000'+ CAST(idfield AS varchar(9))),9 )+'FAK')



这将给你invoiceno格式:



AS000000001FAK

AS000000002FAK

...

AS000995481FAK
adding a prefix/suffix. Something like this should work:

1 - Add an IDENTITY field which will be auto-incremented
2 - Add a calculated field in the table with the definition of:

[InvoiceNo] AS ('AS' + RIGHT(('000000000' + CAST(idfield AS varchar(9))), 9) + 'FAK')

This will give you invoiceno in the format of:

AS000000001FAK
AS000000002FAK
...
AS000995481FAK


这篇关于如何在asp.net中自动生成和记录数据库中用户的唯一ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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