Date.MaxValue

  • Thread starter Thread starter Scott D
  • Start date Start date
S

Scott D

I am trying to get around the SQL Null Date issue by using
Date.MaxValue. When I enter the information into the db I use the
following code:

If Me.test.Text = "" Then
test = Date.MaxValue
Else
test = Me.test.Text
End If

The dates go in fine. However when I try to check for Date.MaxValue
using this code:

If Not dr("test") = Date.MaxValue Then
Me.test.Text = dr("test")
End If

The if statement never evaluates to true even though the MaxValue date
is being read from the database.

Any clue as to why this evaluation would be failing?
 
Hi Scott,

You should really avoid *not* using Option Strict.
There is type converting going on between string and DateTime.
Set your datatable column to DateTime instead of string.
However, if you insist on strings then you should use

if dr("test") = Convert.ToString(DateTime.MaxValue) then
 
well the real problem [besides not having Option Strict On... BAD!] is that
Sql's DateTime maxvalue is a lot less then the framework DateTime's
MaxValue, I assume the Sql ADO.Net provider is coercing the maxvalue to
Sql's max and then pulling it out that way, so DateTime.MaxValue will never
equal a Sql DateTime Maxvalue
 
I am very new to this and am working my way through as best I can.
Could you possibly give me an explanation and example of how my code
should look using Option Strict = On? I really want to do this right
but because of a deadline have found a work around for the issue by
giving a set minimum date (I did have SQL field set to datetime).

Any help you guys could give on Option Strict and how I should be
using it would be great. I do try and do things right but sometimes
getting through it helps me learn.
 
Back
Top