本文介绍了.NET日期时间为SQLDATETIME转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在转换.NET日期时间(时为默认(日期时间)),以SQLDATETIME我要经常检查.NET日期是SqlDateTime.MinValue和SqlDateTime.MaxValue [或]之间有什么好办法做到这一点。

While converting .NET DateTime (when is default(DateTime)) to SqlDateTime should I always check if the .NET date is between SqlDateTime.MinValue and SqlDateTime.MaxValue [or] Is there a good way to do this.

推荐答案

难道日期可能实际上是在该范围之外?它来自用户的输入?如果答案要么这些问题是肯定的,那么你应该经常检查 - 否则你要离开你的应用程序容易出错

Is it possible that the date could actually be outside that range? Does it come from user input? If the answer to either of these questions is yes, then you should always check - otherwise you're leaving your application prone to error.

您可以格式化你的日期列入SQL语句相当容易:

You can format your date for inclusion in an SQL statement rather easily:

var sqlFormattedDate = myDateTime.Date.ToString("yyyy-MM-dd HH:mm:ss");

这篇关于.NET日期时间为SQLDATETIME转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 16:01