使用SQL Server在VB.net中生成自动编号 [英] Generate Auto Number in VB.net with SQL Server
本文介绍了使用SQL Server在VB.net中生成自动编号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一张桌子
-tblItem(id,name,category)
ID |名称|分类|
001书籍纸
002钢笔作家
003 Pencel Writer
我希望像那样生成它
ID |名称|类别
PD-001PP书签
PD-002WR钢笔作家
PD-003WR Pencel Writer
I Have a table
-tblItem (id,name,category)
ID | Name | Category |
001 Books Paper
002 Pen Writer
003 Pencel Writer
and i want to generate it like that
ID | Name | Category
PD-001PP Book Paper
PD-002WR Pen Writer
PD-003WR Pencel Writer
推荐答案
您可以将ID列设置为关闭身份的主键。
然后,每当您通过VB插入新记录时/>
1)获取最后一个ID。
2)解析字符串以获取右边的数字,例如001等
3)将其增加1
4)将产品代码附加到此数字,例如'PD-'+ 004
5)插入新行
You can set the ID column to a primary key with identity turned off.
Then, whenever you insert a new record through VB
1) get the last ID.
2) parse the string to get the number at the right for e.g. 001 etc
3) increment it by 1
4) append the product code to this number for e.g. 'PD-' + 004
5) insert the new row
这篇关于使用SQL Server在VB.net中生成自动编号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文