如何在asp.net中将0000保存到数据库 [英] how to save 0000 to database in asp.net

查看:67
本文介绍了如何在asp.net中将0000保存到数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们,我必须存储4位数的文本框值,并提供检查可用性。我做了一些像盯着1000,1154,1001等的值,但我不能存储像0 0000,0120,0010,0001等开始的值...请帮助我..如何存储这些类型的值...我在等你的回复...谢谢你请帮助我............

解决方案

你可以将值作为VARCHAR存储在数据库中,然后您将保留格式。但是,这个解决方案可能会在稍后回来并咬在后面。

例如,如果你想改成5或6位数怎么办?


您对如何存储值以及如何在屏幕上为用户显示值感到困惑。



使用数据类型INT不是问题并存储值1,2,3等。



问题在于您如何向用户展示价值。在这种情况下,您将值格式设置为始终显示左边用零填充的数字。



  =  1 ; 
Console.WriteLine( value .ToString( 0000));





 Console.WriteLine(字符串 .Format(  {0:0000} value )); 



两个版本都会产生输出'0001'

将来如果你想从4位数改为5位,你就不必费心去打扰数据层,只需要表达层。



自定义数字格式字符串 [ ^ ]了解更多信息。


hi friends i have to store text box value like 4 digits with check availability . i done some values like stared with 1..like 1000,1154,1001,etc but i can not store the values started with 0's like 0000,0120,0010,0001,etc...please help me..how to store these type's of values..i am waiting for your reply...thank you please help me............

解决方案

You could store the values in the database as a VARCHAR, then you will keep your formatting. However, this solution will probably come back and bite in the rear later on.
For example, what if you want to change to 5 or 6 digits?

You are confusing how values are stored with how values are presented on the screen for a user.

It is not a problem to use the datatype INT and store values like 1, 2, 3 etc.

The thing is how you present the value to a user. In this case you format the value to always show for digits left padded with zeros.

value = 1;
Console.WriteLine(value.ToString("0000"));


or

Console.WriteLine(String.Format("{0:0000}", value));


Both versions will result in the output '0001'
And in the future if you like to change from 4 to 5 digits you don't have to bother the data layer, just the presentation layer.

See Custom Numeric Format Strings[^] for more information.


这篇关于如何在asp.net中将0000保存到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆