Null date in vb.net

A3056

New member
Joined
Jul 13, 2005
Messages
1
Programming Experience
Beginner
I am trying to get value from database that is null, but what is happening that it is comin in as
#1/1/1900# or #12:00:00 AM#
. In the sp the value is defined as Datetime
What I want is that when a value comes and its null then the program should return Nothing.Just blank "".
Here is my Property, method and application view.Please help on how can I get rid of this #1/1/1900# or #12:00:00 AM# or #1/1/190012:00:00 AM#.

--Property
PublicProperty 1Date() AsDate
Get
1Date= _1Date.ToShortDateString
EndGet
Set(ByVal Value AsDate)
_1Date= Value
EndSet
EndProperty

--Methods

PublicFunction Get info()
If Not dr("@1Date") Is DBNull.Value Then
.1Date= (Convert.ToDateTime(dr("@1Date")))
End If
Endfunction

--application
dt = New DataTable
dt.Columns.Add(New DataColumn("1Date", GetType(String)))
Dim dr As DataRow = dt.NewRow()
dr= .1Date.ToShortDateString

 
Wrong approach ...

It should look something like this

If cmd.ExecuteScalar Is DBNull.Value Then
text1.text = ""
Else
>>>

Because, you cannot leave datareader to read DBNull ... an eception will be thrown

But rather you should separetely check if field is DBEmpty

Cheers :)
 
Last edited:
Back
Top