Click here to Skip to main content
11,922,905 members (48,304 online)
Rate this:
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:


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
CHill60 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 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
Please Sign up or sign in to vote.

Solution 1


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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.151125.1 | 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