使用SQL Server 2005将Empty MaskedTextBox值插入日期字段 [英] Inserting Empty maskedtextbox value into date field using sql server 2005

查看:86
本文介绍了使用SQL Server 2005将Empty MaskedTextBox值插入日期字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以我的形式

我的日期值有一个maskedtextbox,如果用户单击CURRENT Button,我的进程将忽略来自maskedtextbox的值为空的值,但是当用户单击PROCESS按钮时,maskedtextbox的值将包括在向我的sql服务器插入新记录中. />
我的maskedtextbox自定义默认值为"00/00/0000"
在运行时中,单击CURRENT按钮,maskedtextbox的值为"//"
如果用户单击处理",则maskedtextbox值将是用户输入的值.

当maskedtextbox为空或值为"//"时,我在保存到sql服务器时出错.

In my form,

I have a maskedtextbox for my date value, If a user clicks CURRENT Button, my process will ignore value from maskedtextbox which is empty, But when user clicks PROCESS button, value from maskedtextbox is included in inserting new record unto my sql server.

My customize default for maskedtextbox is "00/00/0000"
in runtime, and CURRENT button is click, maskedtextbox value is " / / "
If the user clicks PROCESS, maskedtextbox value will be what the User enters.

I''m having error saving to sql server when maskedtextbox is empty or value is " / /".

推荐答案

你好,

您的datetime列是否接受空值.如果是,那么当用户按下CURRENT Button时为什么不传递空值.

谢谢
sanjeev.
Hello,

does your datetime column accepts null value. if yes then why dont you pass null value when user press CURRENT Button.

Thanks
sanjeev.


如果您使用的是SQL Date字段,则无论如何都会插入该错误:所有此类日期的格式均遵循ISO标准"yyyy-MM-dd". br/>
1)将您的MaskedTextBox转换为DateTime.报告任何错误,因为它们指示错误的日期,无论如何这都会在SQL Server上导致错误.
2)将DateTime值作为参数传递给数据库.如果您的数据库字段接受空值,那么您可能希望将其传递给空字段.

您可能要考虑使用DateTimePicker而不是文本框,因为用户无法使用thet输入错误的日期,并且它已经自动为您提供了DateTime值.
You will have an error inserting it anyway, if you are using an SQL Date field: the format for all such dates follows the ISO standard "yyyy-MM-dd".

1) Convert your MaskedTextBox to a DateTime. Report any errors, as they indicate bad dates which would cause an error on SQL Server anyway.
2) Hand the DateTime value to the database as a Parameter. If your database field accepts nulls, then you might want to pass that for empty fields instead.

You might want to consider using a DateTimePicker instead of a textbox, as teh user cannot enter a bad date with thet, and it already gives you a DateTime value automatically.


这篇关于使用SQL Server 2005将Empty MaskedTextBox值插入日期字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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