Link to home
Start Free TrialLog in
Avatar of kanden
kanden

asked on

SQLServer and ASP.net (using identity)

I need to set the identity so that it shows 5 digits 00001. I'm not sure what the best method is.

Should I leave the identity seed at 1 and only show the zeros on the .net page.

or

Is there a way to get SQL Server to seed showing the zeros??

Thanks
Avatar of eozz_2000
eozz_2000

I recomment to fill the spaces that you need with strVariable.padLeft(5,"0"), in that way you still have the clarity of your dataBase design... well, thats my opinion.
Avatar of kanden

ASKER

That will work but what do I do when the identity gets to 2 digits that whould produce 000012 that whould make the number 6 digits instead of five. Is there a way to script this?

Gary
SOLUTION
Avatar of eozz_2000
eozz_2000

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kanden

ASKER

That works except it puts 4 zeros regardless of how many digits the identity is.

I need a max of 5 digits zeros plus the identity. example 00125 or 00001 or 12345

Thanks

Gary
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
In VB.NET

Dim myInt1 As Integer = 11
Dim myInt2 As Integer = 12345

Dim s1 As String = myInt1.ToString("00000")     // returns 00011
Dim s2 As String = myInt2.ToString("00000")     // returns 12345
jeje... that thing you didn't say with your comment:

"That will work but what do I do when the identity gets to 2 digits that whould produce 000012 that whould make the number 6 digits instead of five. Is there a way to script this?"

you asked for a 6 digits, well, anyway the problem is solved.