Search code examples
c#sqldatabasedigit

how to store number in double digit format?


I have 100 textboxes in 00 to 99 manners in form. I want to store first 0 to 9 in double digit format like 00, 01, 02, .... 09. How can i store it in sql database in that format without making it a string. I am doing project in c#.


Solution

  • If you need to have those values in that format just in your table;
    You need to run a query to insert a new row or update a valid row;

    string query = string.format("Insert Into <table name> Values (list of values)", int value(s));
    

    or

    string query = string.format("UPDATE <table name> Set (list of '<field name> = <value>'s)", int value(s));
    

    You need just use {0:00} instead of {0} in your query string.

    If you use sqlCommand at setting parameters use it in this way = string("{0:00}", int value)

    Note: all codes are sample, you need to generate your own codes.

    If you need to store your value with format you should use one of char data-types in your table.