Solved

SQLServer and ASP.net (using identity)

Posted on 2004-10-04
7
149 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Duplicate a row 2 46
.net VBA word safemode 1 35
No row return after calling the fillschema method 4 39
Receiving a string from a WebService Push 21 31
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

948 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

22 Experts available now in Live!

Get 1:1 Help Now