如何以两位数格式存储数字?

how to store number in double digit format?

我有 100 个格式为 00 到 99 的文本框。我想以双位数格式存储第一个 0 到 9,例如 00、01、02、.... 09。如何以这种格式将其存储在 sql 数据库中而不将其设为字符串。我正在用 c# 做项目。

如果您需要在 table;
中使用该格式的这些值 您需要 运行 查询以插入新行或更新有效行;

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

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

您只需在查询字符串中使用 {0:00} 而不是 {0}

如果你在设置参数的时候用sqlCommand就这样用= string("{0:00}", int value)

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

如果您需要使用格式存储您的值,您应该在 table.

中使用 char 数据类型之一

如果你的申请是"int",我想是不可能的。因为 09 是整数 9。根据整数的经验法则,前导零没有值。

但您始终可以 SELECT 格式化,或者根据需要使用 "varchar" 类型来存储它。

希望我说得够清楚..!!