Solved

SQLServer and ASP.net (using identity)

Posted on 2004-10-04
7
155 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Suggested Courses

632 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