Click here to Skip to main content
11,410,750 members (62,085 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB VB.NET
Hello there.

Is there a way to maintain the format of a number in this form:

00238
00250

Initially those numbers are a string in the project and they are saved as varchar in my database, but I need to generate a consecutive serial from those two, to achieve that I pass the numbers to int, but with this the leading zeros are obviously removed.
Is just to clear my curiosity about it, I already save all the serials into the database with the leading zeros but I made this taking the length of the original string and making a comparison of the serial generated with the original.

Thanks in advance
Posted 21-Feb-13 5:42am
Edited 21-Feb-13 5:49am
v2
Comments
CHill60 at 21-Feb-13 11:10am
   
Just a thought - you will get better database performance if you stored these "numbers" as integers on the database. You will also future-proof yourself against the serial number clocking past 99999. You can always display/print them in the varchar format when required. Another advantage would be being able to have the d/base column defined with IDENTITY(1,1) meaning that the serial will be automatically incremented for you each time you add a row
EddyGuzman at 21-Feb-13 11:42am
   
Oh! Yes I know, I was saving them as Integers at start, problem is that this numbers are consecutive serials, so if I remove the zeros the serial will be incorrect. But your comment is absolutely valid.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 239
1 Sascha Lefévre 85
2 Dave Kreskowiak 80
3 Maciej Los 68
4 RyanDev 50
0 Sergey Alexandrovich Kryukov 8,885
1 OriginalGriff 6,915
2 Maciej Los 3,390
3 Abhinav S 3,248
4 Peter Leow 3,059


Advertise | Privacy | Mobile
Web04 | 2.8.150414.5 | Last Updated 21 Feb 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100