开发者

How to check if the user enters the default datetime?

开发者 https://www.devze.com 2023-03-14 22:08 出处:网络
I have two textboxes on the screen. They are used for star开发者_开发知识库tdate and enddate. If the user does not enter anything in the textboxes I pass nothing (VB.NET) to the webservice. When the w

I have two textboxes on the screen. They are used for star开发者_开发知识库tdate and enddate. If the user does not enter anything in the textboxes I pass nothing (VB.NET) to the webservice. When the webservice receive it on the other end it shows the value "#12:00:00 AM" which I think is the default for the datetime field. Anyway, now I do not want to pass this value to Stored procedure since it will not work. How can I check before sending values to sproc that the value is not the default datetime.


If you don't want to pass it to the WebService, why do you pass it anyway?

To see if a Date is not the "default-date":

If Not Date.MinValue = MyDate


I can think of two options here.

  1. Since you already know that you're receiving "#12:00:00AM" when the field is not filled in, check if the value you receive is "#12:00:00AM".

  2. Prior to passing the value to your stored procedure, create a new DateTime object. Compare the value you're receiving against the value in the new DateTime object.


Instead of DateTime use Nullable of DateTime. Then you can pass a null (or nothing) value to the web service and you use Date.HasValue to check if a value was entered/passed.

0

精彩评论

暂无评论...
验证码 换一张
取 消