Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 159
  • Last Modified:

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
0
kanden
Asked:
kanden
  • 3
  • 2
  • 2
2 Solutions
 
eozz_2000Commented:
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.
0
 
kandenAuthor Commented:
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
0
 
eozz_2000Commented:
you can make something like this:

strVariable = strVariable.padLeft(strVariable.length + 4, "0")
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
kandenAuthor Commented:
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
0
 
ihenryCommented:
try this,

int myInt1 = 11;
int myInt2 = 12345;

string s1 = myInt1.ToString("00000");      // returns 00011
string s2 = myInt1.ToString("00000");      // returns 12345
0
 
ihenryCommented:
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
0
 
eozz_2000Commented:
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.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now