本文介绍了id生成器代码问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你做编码器..我面临着我的id号码生成器代码的问题
i我正在构建数据库项目,我想让id自动生成它我自己做了但不是我想要的它工作...我希望它从001开始增加每次+1喜欢这个002,003直到它达到100等等
它现在如何工作就像这从1开始然后2 ,3,4,5,6 ......这是代码。
谢谢。
hw u doing coders .. am facing problem with my code of id number generator
i am building database project and i want to make the id generates it self automaticaly i did it but not how i want it to work ...i want it to Start from 001 and increases every time +1 like this 002,003 untill it reach 100 and so on
how it works now is like this starts from 1 and then 2,3,4,5,6......here is the code.
thank you.
Sub GenerateSerialNo()
Dim odr As SqlDataReader
Dim sql As String
sql = "select max(bookid)as SNo from tbremovedbooks"
Try
conn.Open()
'Application.DoEvents()
cmd = New SqlCommand(sql, conn)
odr = cmd.ExecuteReader
If odr.Read() Then
iNumOfRecords = DS.Tables("tbremovedbooks").Rows.Count + 1
'Displaying 1 if there is no data in the table
If iNumOfRecords = 1 Then
txtbookid.Text = "1"
Else
'Ordering the data Serial if more than one record is in the table
txtbookid.Text = odr("SNo") + 1
End If
End If
odr.Close()
cmd.Connection.Close()
conn.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
推荐答案
string formattedId = id.ToString("000");
简单有效。
Simple, and effective.
这篇关于id生成器代码问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!