如何检查我输入的日期是否对SqlServer有效? [英] How to check my entered date is valid for SqlServer or not?

查看:619
本文介绍了如何检查我输入的日期是否对SqlServer有效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我遇到过一个问题。



我有一个文本框日历扩展程序,maskededit编辑器和mastededit验证程序,对于输入日期11/11/1111(MM / dd / yyyy)无效,当此日期传递给Sql server时它给我SqlTypeException,所以在代码后面我想要在我将它传递给Sql之前检查日期是否对Sql服务器有效。



任何人都有这个想法???



请帮帮我这个???

Hello,

I have stuck with one issue.

I have a one textbox with calendar extender ,maskededit editor and mastededit validator ,which is could not valid for enter date 11/11/1111(MM/dd/yyyy) ,when this date pass to Sql server it is giving me SqlTypeException ,so in code behind i want to check the date is valid for Sql server or not before i pass it to Sql .

Any one has ideas about that???

Please help me out this???

推荐答案

你可以将DateTime传递给DbCommand / SqlCommand并记住Sql server的命令第一个有效日期是1973年1月1日提到的这里 [ ^ ]
You can pass a DateTime to DbCommand/SqlCommand and keep in mind for Sql server the first valid date is 1/1/1973 as mentioned here[^]


ya但我不想t允许生成exception.i想在我将日期传递给sql之前检查它。



顺便说一下我从下面的链接获得解决方案



http:/ /stackoverflow.com/questions/7054782/validate-datetime-before-inserting-it-into-sql-server-database [ ^ ]
ya but i don''t want to allow generate exception.i want to check it before i pass the date to sql.

by the way i got the solutions from below link

http://stackoverflow.com/questions/7054782/validate-datetime-before-inserting-it-into-sql-server-database[^]





sql server中的默认日期格式是YYYY / MM / DD。

我的建议是在执行查询之前使用命令set dateformat在sql server中指定要插入或更新数据库的日期格式。



到年份问题请参阅 http://msdn.microsoft.com/en-us/library/bb 677335.aspx [ ^ ]



干杯,

JAFC
Hi,

The default date format in sql server is YYYY/MM/DD.
My recommendation is to use the command "set dateformat" before execute your query in sql server to specify the date format that you will insert or update the database.

To the year question see http://msdn.microsoft.com/en-us/library/bb677335.aspx[^]

Cheers,
JAFC


这篇关于如何检查我输入的日期是否对SqlServer有效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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