将数据输入到SQL Server时的格式 [英] Format when entering data into sql server

查看:108
本文介绍了将数据输入到SQL Server时的格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据库,电话号码为nvarchar,一个单元格为数字.

我都将其格式化为###-###-####.

我有两个问题.

问题1.

员工输入数字时除格式外如何制作?

问题2:

当员工去保存时,它给出了一条错误消息,无法用破折号保存.

都没有尝试过.

这是asp.net/c#问题吗?
或数据库问题.

所以我会知道要研究什么.

I have a database with phone number nvarchar, and a cell as numeric.

I formatted both as ###-###-####.

I have two question.

Question 1.

When a employee enter the number how to make except the format?

Question 2.

when a employee go to save it gives an error message can''t save with the dashes.

Tried both neither works.

Is this a asp.net /c# problem
or database issues.

So I will know what to research.

推荐答案

只是Google或使用CodeProject搜索蒙版文本框
Just Google or use CodeProject search for Masked textbox!


好吧,如果您确实向我们提供了有用的信息,我们可以为您提供更多帮助.您说它给您一条错误消息...确切的错误消息是什么?另外,发布您正在使用的代码和示例数据,以便我们确切地知道您要执行的操作.

我的猜测是您正在尝试将字符串值插入数字字段.您必须删除破折号,解析字符串(也许是十进制?),然后将该值插入数字字段.没有更多信息,这是我能给您的最佳猜测.

就像提到的其他海报一样,请使用带遮罩的文本框,也可以创建多个文本框,并在每个文本框上放置一个验证器,以确保它们的格式正确.就个人而言,我可能会在单个文本框上放置一个正则表达式验证器,并允许用户输入其电话号码的多种格式.
Well, we could help you more if you actually gave us useful information. You say it gave you an error message... what was the exact error message? Also, post the code you''re using and the sample data so we know exactly what you''re trying to do.

My guess is you are trying to insert a string value into a numeric field. You''d have to remove the dashes, parse the string (perhaps as Decimal?), then insert that value into the numeric field. Without more information, that''s the best guess I can give you.

Like another poster mentioned, use a masked textbox, or you can create multiple textboxes and put a validator on each of them to ensure they are in the right format. Personally, I''d probably put a regular expression validator on a single textbox and allow the user to enter multiple formats for their phone number.


我认为您可以在表示层上进行处理.而不是使用一个电话号码文本框,请尝试使用3个由-"分隔的文本框,分别限制字符数为3、3和4.
I think you can handle this on your presentation layer. Instead of having one textbox for phone number, try with 3 textboxes separated by "-" with character limits of 3, 3 and 4 respectively.


这篇关于将数据输入到SQL Server时的格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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