Click here to Skip to main content
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 George Jonsson 215
1 Kornfeld Eliyahu Peter 169
2 OriginalGriff 120
3 PIEBALDconsult 110
4 BillWoodruff 85
0 OriginalGriff 6,165
1 DamithSL 4,658
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,649
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 21 Feb 2013
Copyright © CodeProject, 1999-2014
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