I need to store an CARD ID number in Database. So there is no calculation just a search of the ID and putting the value in Session as property in a class.
The is ID is always numeric and it’s 12 positions.
e.g. 123456789012 and I would like to show on the screen in this format. 123.456.789.012 (every 3 digit a dot).
I tried a test and defined Decimal(12,0) in database and I have put this value in database: 555666777888
then I try to display on the screen I used this code (CardID is decimal):
lblCardID.Text = ent.CardID.ToString("0:#,###")
but it shows on the screen like this: 555,666,77:7,888
where is the colon (:) coming from?
question additional:
– What type shall use in MS SQL to store this value in Database. Decimal (12,0) or Nvarchar(12) ?
I would use
bigintbecause it needs only 8 bytes per value.decimal(12,0)needs 9 bytes andvarcharornvarchareven more (12 or 24 bytes respectively in case of storing 12 digits).Smaller column size makes indexes smaller, which make indexes faster in use.
Formatting numbers can be done in application.
It’s also much easier to change formatting in app in case of requirements change.