Solved

SQLServer and ASP.net (using identity)

Posted on 2004-10-04
7
148 Views
Last Modified: 2012-05-05
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
Comment
Question by:kanden
  • 3
  • 2
  • 2
7 Comments
 
LVL 4

Expert Comment

by:eozz_2000
ID: 12222040
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
 

Author Comment

by:kanden
ID: 12222155
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
 
LVL 4

Assisted Solution

by:eozz_2000
eozz_2000 earned 100 total points
ID: 12222167
you can make something like this:

strVariable = strVariable.padLeft(strVariable.length + 4, "0")
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:kanden
ID: 12222755
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
 
LVL 20

Accepted Solution

by:
ihenry earned 150 total points
ID: 12223588
try this,

int myInt1 = 11;
int myInt2 = 12345;

string s1 = myInt1.ToString("00000");      // returns 00011
string s2 = myInt1.ToString("00000");      // returns 12345
0
 
LVL 20

Expert Comment

by:ihenry
ID: 12223598
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
 
LVL 4

Expert Comment

by:eozz_2000
ID: 12223646
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now